Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • car/libdap-crypto
1 result
Show changes
Commits on Source (64)
Showing
with 3670 additions and 64 deletions
......@@ -3,15 +3,7 @@ project (dap_crypto)
# fix implicit declaration warnings
add_definitions ("-D_GNU_SOURCE")
#set(CMAKE_C_FLAGS "-std=c11 -O2 -Wall -Wextra -fPIC -fno-pie -no-pie -fno-ident ")
#set(CMAKE_ASM_FLAGS "-std=c11 -O2 -Wall -Wextra -fPIC -fno-pie -no-pie -fno-ident ")
#set(CMAKE_C_FLAGS "-std=c11 -O3 -Wall -Wextra -fPIC -fno-pie -no-pie -fno-ident -ffast-math -ftree-vectorize -mfpmath=sse -mmmx -msse2 -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all")
#set(CMAKE_ASM_FLAGS "-std=c11 -O3 -Wall -Wextra -fPIC -fno-pie -no-pie -fno-ident -ffast-math -ftree-vectorize -mfpmath=sse -mmmx -msse2 -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all")
#set(CMAKE_C_FLAGS "-static -Wall -O3 -fno-ident -ffast-math -ftree-vectorize -mfpmath=sse -mmmx -msse2 -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all")
#set(CMAKE_ASM_FLAGS "-static -Wall -O3 -fno-ident -ffast-math -ftree-vectorize -mfpmath=sse -mmmx -msse2 -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all")
if(NOT (${SUBMODULES_NO_BUILD} MATCHES ON))
if(NOT SUBMODULES_NO_BUILD)
# Check whether we're on a 32-bit or 64-bit system
if(CMAKE_SIZEOF_VOID_P EQUAL "8")
......@@ -21,8 +13,6 @@ if(NOT (${SUBMODULES_NO_BUILD} MATCHES ON))
endif()
option(BUILD_64 "Build for 64-bit? 'OFF' builds for 32-bit." ${DEFAULT_BUILD_64})
add_definitions ("-DDAP_SERVER")
add_definitions ("-DNODE_NETNAME=\"cellframe\"")
set(_CCOPT "-Wall -O2 -pg -fPIC -fno-pie -no-pie")
set(_LOPT "-pg")
......@@ -35,40 +25,50 @@ if(NOT (${SUBMODULES_NO_BUILD} MATCHES ON))
endif()
endif()
file( GLOB CRYPTO_SRCS
src/*.c
src/rand/*.c
src/iaes/*.c
src/oaes/*.c
src/sha3/*.c
src/msrln/*.c
src/defeo_scheme/*.c
src/sig_bliss/*.c
src/sig_tesla/*.c
file( GLOB CRYPTO_SRCS
src/*.c
src/rand/*.c
src/iaes/*.c
src/oaes/*.c
src/blowfish/*.c
src/GOST/*.c
src/salsa2012/*.c
src/seed/*.c
src/sha3/*.c
src/msrln/*.c
src/defeo_scheme/*.c
src/sig_bliss/*.c
src/sig_tesla/*.c
src/sig_picnic/*.c
src/sig_dilithium/*.c
src/ringct20/*.c
)
file( GLOB CRYPTO_HEADERS
src/*.h
src/rand/*.h
src/iaes/*.h
src/oaes/*.h
src/sha3/*.h
src/msrln/*.h
src/defeo_scheme/*.h
src/sig_bliss/*.h
src/sig_tesla/*.h
src/sig_picnic/*.h
file( GLOB CRYPTO_HEADERS
src/*.h
src/rand/*.h
src/iaes/*.h
src/oaes/*.h
src/blowfish/*.h
src/GOST/*.h
src/salsa2012/*.h
src/seed/*.h
src/sha3/*.h
src/msrln/*.h
src/defeo_scheme/*.h
src/sig_bliss/*.h
src/sig_tesla/*.h
src/sig_picnic/*.h
src/sig_dilithium/*.h
src/ringct20/*.h
include/*.h
)
enable_language(ASM)
file( GLOB XKCP_SRCS
src/XKCP/lib/high/Keccak/FIPS202/KeccakHash.c
src/XKCP/lib/high/Keccak/KeccakSpongeWidth1600.c
file( GLOB XKCP_SRCS
#src/XKCP/lib/high/Keccak/FIPS202/KeccakHash.c
#src/XKCP/lib/high/Keccak/KeccakSpongeWidth1600.c
src/XKCP/lib/high/Keccak/SP800-185/SP800-185.c
src/XKCP/lib/high/Keccak/FIPS202/SimpleFIPS202.c
)
......@@ -278,6 +278,7 @@ if(UNIX)
target_link_libraries(dap_crypto dap_core m)
endif()
if(BUILD_CRYPTO_TESTS)
enable_testing()
add_subdirectory(test)
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.11.2, 2020-04-29T10:52:27. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
<value type="QByteArray">{11b3ace2-edb6-4ae7-8e1b-fce9fa91893f}</value>
</data>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="int">0</value>
</data>
<data>
<variable>ProjectExplorer.Project.EditorSettings</variable>
<valuemap type="QVariantMap">
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
<value type="QString" key="language">Cpp</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
</valuemap>
</valuemap>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
<value type="QString" key="language">QmlJS</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
</valuemap>
</valuemap>
<value type="int" key="EditorConfiguration.CodeStyle.Count">2</value>
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
<value type="int" key="EditorConfiguration.IndentSize">4</value>
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
<value type="int" key="EditorConfiguration.TabSize">8</value>
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap">
<valuelist type="QVariantList" key="ClangCodeModel.CustomCommandLineKey">
<value type="QString">-fno-delayed-template-parsing</value>
</valuelist>
<value type="bool" key="ClangCodeModel.UseGlobalConfig">true</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.14.2 MinGW 32-bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.14.2 MinGW 32-bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt5.5142.win32_mingw73_kit</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<valuelist type="QVariantList" key="CMake.Configuration">
<value type="QString">BUILD_CRYPTO_TESTS:BOOL=ON</value>
<value type="QString">CMAKE_BUILD_TYPE:STRING=Debug</value>
<value type="QString">CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx}</value>
<value type="QString">CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C}</value>
<value type="QString">CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}</value>
<value type="QString">QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable}</value>
</valuelist>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:/qt_proj/build-libdap-crypto_new-Desktop_Qt_5_14_2_MinGW_32_bit-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">all</value>
</valuelist>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">clean</value>
</valuelist>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<valuelist type="QVariantList" key="CMake.Configuration">
<value type="QString">CMAKE_BUILD_TYPE:STRING=Release</value>
<value type="QString">CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx}</value>
<value type="QString">CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C}</value>
<value type="QString">CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}</value>
<value type="QString">QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable}</value>
</valuelist>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:/qt_proj/build-libdap-crypto_new-Desktop_Qt_5_14_2_MinGW_32_bit-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">all</value>
</valuelist>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">clean</value>
</valuelist>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
<valuelist type="QVariantList" key="CMake.Configuration">
<value type="QString">CMAKE_BUILD_TYPE:STRING=RelWithDebInfo</value>
<value type="QString">CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx}</value>
<value type="QString">CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C}</value>
<value type="QString">CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}</value>
<value type="QString">QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable}</value>
</valuelist>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:/qt_proj/build-libdap-crypto_new-Desktop_Qt_5_14_2_MinGW_32_bit-RelWithDebInfo</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">all</value>
</valuelist>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">clean</value>
</valuelist>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Release with Debug Information</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.3">
<valuelist type="QVariantList" key="CMake.Configuration">
<value type="QString">CMAKE_BUILD_TYPE:STRING=MinSizeRel</value>
<value type="QString">CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx}</value>
<value type="QString">CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C}</value>
<value type="QString">CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}</value>
<value type="QString">QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable}</value>
</valuelist>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:/qt_proj/build-libdap-crypto_new-Desktop_Qt_5_14_2_MinGW_32_bit-MinSizeRel</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">all</value>
</valuelist>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
<value type="QString">clean</value>
</valuelist>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Minimum Size Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">4</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="QString" key="Analyzer.Perf.CallgraphMode">dwarf</value>
<valuelist type="QVariantList" key="Analyzer.Perf.Events">
<value type="QString">cpu-cycles</value>
</valuelist>
<valuelist type="QVariantList" key="Analyzer.Perf.ExtraArguments"/>
<value type="int" key="Analyzer.Perf.Frequency">250</value>
<valuelist type="QVariantList" key="Analyzer.Perf.RecordArguments">
<value type="QString">-e</value>
<value type="QString">cpu-cycles</value>
<value type="QString">--call-graph</value>
<value type="QString">dwarf,4096</value>
<value type="QString">-F</value>
<value type="QString">250</value>
</valuelist>
<value type="QString" key="Analyzer.Perf.SampleMode">-F</value>
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="int" key="Analyzer.Perf.StackSize">4096</value>
<value type="bool" key="Analyzer.QmlProfiler.AggregateTraces">false</value>
<value type="bool" key="Analyzer.QmlProfiler.FlushEnabled">false</value>
<value type="uint" key="Analyzer.QmlProfiler.FlushInterval">1000</value>
<value type="QString" key="Analyzer.QmlProfiler.LastTraceFile"></value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
<value type="QString" key="Analyzer.Valgrind.KCachegrindExecutable">kcachegrind</value>
<value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">1</value>
<value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
<value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">1</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.Valgrind.ShowReachable">false</value>
<value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
<value type="int">0</value>
<value type="int">1</value>
<value type="int">2</value>
<value type="int">3</value>
<value type="int">4</value>
<value type="int">5</value>
<value type="int">6</value>
<value type="int">7</value>
<value type="int">8</value>
<value type="int">9</value>
<value type="int">10</value>
<value type="int">11</value>
<value type="int">12</value>
<value type="int">13</value>
<value type="int">14</value>
</valuelist>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">crypto-test</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeRunConfiguration.crypto-test</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">crypto-test</value>
<value type="QString" key="RunConfiguration.Arguments"></value>
<value type="bool" key="RunConfiguration.Arguments.multi">false</value>
<value type="QString" key="RunConfiguration.OverrideDebuggerStartup"></value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory"></value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default"></value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.1">
<value type="QString" key="Analyzer.Perf.CallgraphMode">dwarf</value>
<valuelist type="QVariantList" key="Analyzer.Perf.Events">
<value type="QString">cpu-cycles</value>
</valuelist>
<valuelist type="QVariantList" key="Analyzer.Perf.ExtraArguments"/>
<value type="int" key="Analyzer.Perf.Frequency">250</value>
<valuelist type="QVariantList" key="Analyzer.Perf.RecordArguments">
<value type="QString">-e</value>
<value type="QString">cpu-cycles</value>
<value type="QString">--call-graph</value>
<value type="QString">dwarf,4096</value>
<value type="QString">-F</value>
<value type="QString">250</value>
</valuelist>
<value type="QString" key="Analyzer.Perf.SampleMode">-F</value>
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="int" key="Analyzer.Perf.StackSize">4096</value>
<value type="bool" key="Analyzer.QmlProfiler.AggregateTraces">false</value>
<value type="bool" key="Analyzer.QmlProfiler.FlushEnabled">false</value>
<value type="uint" key="Analyzer.QmlProfiler.FlushInterval">1000</value>
<value type="QString" key="Analyzer.QmlProfiler.LastTraceFile"></value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
<value type="QString" key="Analyzer.Valgrind.KCachegrindExecutable">kcachegrind</value>
<value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">1</value>
<value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
<value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">1</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.Valgrind.ShowReachable">false</value>
<value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
<value type="int">0</value>
<value type="int">1</value>
<value type="int">2</value>
<value type="int">3</value>
<value type="int">4</value>
<value type="int">5</value>
<value type="int">6</value>
<value type="int">7</value>
<value type="int">8</value>
<value type="int">9</value>
<value type="int">10</value>
<value type="int">11</value>
<value type="int">12</value>
<value type="int">13</value>
<value type="int">14</value>
</valuelist>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">crypto_cert_test</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeRunConfiguration.crypto_cert_test</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">crypto_cert_test</value>
<value type="QString" key="RunConfiguration.Arguments"></value>
<value type="bool" key="RunConfiguration.Arguments.multi">false</value>
<value type="QString" key="RunConfiguration.OverrideDebuggerStartup"></value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory"></value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default"></value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">2</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.TargetCount</variable>
<value type="int">1</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
<value type="int">22</value>
</data>
<data>
<variable>Version</variable>
<value type="int">22</value>
</data>
</qtcreator>
......@@ -59,6 +59,7 @@ dap_cert_t * dap_cert_generate_mem(const char * a_cert_name, dap_enc_key_type_t
dap_cert_t * dap_cert_add_file(const char * a_cert_name,const char *a_folder_path);
int dap_cert_save_to_folder(dap_cert_t * a_cert, const char *a_file_dir_path);
const char* dap_cert_get_folder(int a_n_folder_path);
void dap_cert_add_folder(const char *a_folder_path);
void dap_cert_dump(dap_cert_t * a_cert);
dap_pkey_t * dap_cert_to_pkey(dap_cert_t * a_cert);
......
#ifndef _DAP_ENC_GOST_H_
#define _DAP_ENC_GOST_H_
#include <stddef.h>
#include "dap_enc_key.h"
#include "GOST/block_chipher.h"
#ifdef __cplusplus
extern "C" {
#endif
void dap_enc_gost_key_delete(struct dap_enc_key *a_key);
void dap_enc_gost_key_generate(struct dap_enc_key * a_key, const void *kex_buf,
size_t kex_size, const void * seed, size_t seed_size, size_t key_size);
//------GOST_OFB---------
void dap_enc_gost_ofb_key_new(struct dap_enc_key * a_key);
size_t dap_enc_gost_ofb_calc_decode_size(const size_t size_in);
size_t dap_enc_gost_ofb_calc_encode_size(const size_t size_in);
size_t dap_enc_gost_ofb_decrypt(struct dap_enc_key * a_key, const void * a_in, size_t a_in_size, void ** a_out);
size_t dap_enc_gost_ofb_encrypt(struct dap_enc_key * a_key, const void * a_in, size_t a_in_size, void ** a_out);
// Writes result ( out ) in already allocated buffer
size_t dap_enc_gost_ofb_decrypt_fast(struct dap_enc_key * a_key, const void * a_in,
size_t a_in_size, void * buf_out, size_t buf_out_size);
// Writes result ( out ) in already allocated buffer
size_t dap_enc_gost_ofb_encrypt_fast(struct dap_enc_key * a_key, const void * a_in,
size_t a_in_size, void * buf_out, size_t buf_out_size);
//------KUZNECHIK_OFB--------------
void dap_enc_kuzn_ofb_key_new(struct dap_enc_key * a_key);
size_t dap_enc_kuzn_ofb_calc_decode_size(const size_t size_in);
size_t dap_enc_kuzn_ofb_calc_encode_size(const size_t size_in);
size_t dap_enc_kuzn_ofb_decrypt(struct dap_enc_key * a_key, const void * a_in, size_t a_in_size, void ** a_out);
size_t dap_enc_kuzn_ofb_encrypt(struct dap_enc_key * a_key, const void * a_in, size_t a_in_size, void ** a_out);
// Writes result ( out ) in already allocated buffer
size_t dap_enc_kuzn_ofb_decrypt_fast(struct dap_enc_key * a_key, const void * a_in,
size_t a_in_size, void * buf_out, size_t buf_out_size);
// Writes result ( out ) in already allocated buffer
size_t dap_enc_kuzn_ofb_encrypt_fast(struct dap_enc_key * a_key, const void * a_in,
size_t a_in_size, void * buf_out, size_t buf_out_size);
#ifdef __cplusplus
}
#endif
#endif
......@@ -22,8 +22,8 @@
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _DAP_ENC_BASE64_H_
#define _DAP_ENC_BASE64_H_
#ifndef _DAP_ENC_BASE58_H_
#define _DAP_ENC_BASE58_H_
#include <stddef.h>
#include <stdint.h>
#include "dap_enc_key.h"
......
#ifndef _DAP_ENC_BF_H_
#define _DAP_ENC_BF_H_
#include <stddef.h>
#include "dap_enc_key.h"
#include"blowfish/blowfish.h"
#ifdef __cplusplus
extern "C" {
#endif
void dap_enc_bf_key_delete(struct dap_enc_key *a_key);
void dap_enc_bf_key_generate(struct dap_enc_key * a_key, const void *kex_buf,
size_t kex_size, const void * seed, size_t seed_size, size_t key_size);
//-----CBC----------
void dap_enc_bf_cbc_key_new(struct dap_enc_key * a_key);
size_t dap_enc_bf_cbc_calc_decode_size(const size_t size_in);
size_t dap_enc_bf_cbc_calc_encode_size(const size_t size_in);
size_t dap_enc_bf_cbc_decrypt(struct dap_enc_key * a_key, const void * a_in, size_t a_in_size, void ** a_out);
size_t dap_enc_bf_cbc_encrypt(struct dap_enc_key * a_key, const void * a_in, size_t a_in_size, void ** a_out);
// Writes result ( out ) in already allocated buffer
size_t dap_enc_bf_cbc_decrypt_fast(struct dap_enc_key * a_key, const void * a_in,
size_t a_in_size, void * buf_out, size_t buf_out_size);
// Writes result ( out ) in already allocated buffer
size_t dap_enc_bf_cbc_encrypt_fast(struct dap_enc_key * a_key, const void * a_in,
size_t a_in_size, void * buf_out, size_t buf_out_size);
//------OFB---------
void dap_enc_bf_ofb_key_new(struct dap_enc_key * a_key);
size_t dap_enc_bf_ofb_calc_decode_size(const size_t size_in);
size_t dap_enc_bf_ofb_calc_encode_size(const size_t size_in);
size_t dap_enc_bf_ofb_decrypt(struct dap_enc_key * a_key, const void * a_in, size_t a_in_size, void ** a_out);
size_t dap_enc_bf_ofb_encrypt(struct dap_enc_key * a_key, const void * a_in, size_t a_in_size, void ** a_out);
// Writes result ( out ) in already allocated buffer
size_t dap_enc_bf_ofb_decrypt_fast(struct dap_enc_key * a_key, const void * a_in,
size_t a_in_size, void * buf_out, size_t buf_out_size);
// Writes result ( out ) in already allocated buffer
size_t dap_enc_bf_ofb_encrypt_fast(struct dap_enc_key * a_key, const void * a_in,
size_t a_in_size, void * buf_out, size_t buf_out_size);
#ifdef __cplusplus
}
#endif
#endif
......@@ -28,10 +28,10 @@ int dap_enc_sig_bliss_key_pub_output(struct dap_enc_key *l_key, void * l_output)
uint8_t* dap_enc_sig_bliss_write_signature(bliss_signature_t* a_sign, size_t *a_sign_out);
bliss_signature_t* dap_enc_sig_bliss_read_signature(uint8_t *a_buf, size_t a_buflen);
bliss_signature_t* dap_enc_sig_bliss_read_signature(const uint8_t *a_buf, size_t a_buflen);
uint8_t* dap_enc_sig_bliss_write_private_key(const bliss_private_key_t* a_private_key, size_t *a_buflen_out);
uint8_t* dap_enc_sig_bliss_write_public_key(const bliss_public_key_t* a_public_key, size_t *a_buflen_out);
bliss_private_key_t* dap_enc_sig_bliss_read_private_key(uint8_t *a_buf, size_t a_buflen);
bliss_private_key_t* dap_enc_sig_bliss_read_private_key(const uint8_t *a_buf, size_t a_buflen);
bliss_public_key_t* dap_enc_sig_bliss_read_public_key(const uint8_t *a_buf, size_t a_buflen);
......@@ -17,7 +17,7 @@ void dap_enc_aes_key_delete(struct dap_enc_key *a_key);
void dap_enc_aes_key_generate(struct dap_enc_key * a_key, const void *kex_buf, size_t kex_size,
const void * seed, size_t seed_size, size_t key_size);
size_t dap_enc_iaes256_calc_decode_size(const size_t size_in);
size_t dap_enc_iaes256_calc_decode_max_size(const size_t size_in);
size_t dap_enc_iaes256_calc_encode_size(const size_t size_in);
size_t dap_enc_iaes256_cbc_decrypt(struct dap_enc_key * a_key, const void * a_in, size_t a_in_size, void ** a_out);
......
......@@ -29,8 +29,7 @@
#include <stddef.h>
#include <time.h>
#include <stdint.h>
#include "dap_common.h"
typedef enum dap_enc_data_type{DAP_ENC_DATA_TYPE_RAW,
......@@ -42,10 +41,20 @@ typedef enum dap_enc_data_type{DAP_ENC_DATA_TYPE_RAW,
typedef enum dap_enc_key_type{ DAP_ENC_KEY_TYPE_IAES, // Symmetric AES
typedef enum dap_enc_key_type{
DAP_ENC_KEY_TYPE_IAES, // Symmetric AES
DAP_ENC_KEY_TYPE_OAES,// from https://github.com/monero-project/monero/tree/master/src/crypto
DAP_ENC_KEY_TYPE_BF_CBC,// BlowFish CBCmode
DAP_ENC_KEY_TYPE_BF_OFB,//BlowFish OFBmode
DAP_ENC_KEY_TYPE_GOST_OFB,//GOST28147_89
DAP_ENC_KEY_TYPE_KUZN_OFB,//GOST28147_14
DAP_ENC_KEY_TYPE_SALSA2012,//SALSA2012//http://www.ecrypt.eu.org/stream/salsa20pf.html//https://ianix.com/pub/salsa20-deployment.html
DAP_ENC_KEY_TYPE_RLWE_NEWHOPE, // "NewHope": key exchange from the ring learning with errors problem
// (Alkim, Ducas, Pöppelmann, Schwabe, USENIX Security 2016 )
// Using the reference C implementation of NewHope
......@@ -110,6 +119,8 @@ typedef enum dap_enc_key_type{ DAP_ENC_KEY_TYPE_IAES, // Symmetric AES
DAP_ENC_KEY_TYPE_SIG_DILITHIUM,
DAP_ENC_KEY_TYPE_SIG_RINGCT20,//ring signature for confidentional transaction
DAP_ENC_KEY_TYPE_NULL = 0
} dap_enc_key_type_t;
......@@ -134,6 +145,8 @@ typedef size_t (*dap_enc_callback_dataop_t)(struct dap_enc_key *key, const void
typedef size_t (*dap_enc_callback_dataop_na_t)(struct dap_enc_key *key, const void *in,
const size_t in_size,void * out, const size_t out_size_max);
typedef size_t (*dap_enc_callback_dataop_na_ext_t)(struct dap_enc_key *key, const void *in,
const size_t in_size,void * out, const size_t out_size_max, const void *extra_param, const int extra_param_len);
typedef int (*dap_enc_callback_sign_op_t)(struct dap_enc_key *key, const void *in,
const size_t in_size,void * out, const size_t out_size_max);
......@@ -162,7 +175,7 @@ typedef size_t (*dap_enc_gen_bob_shared_key) (struct dap_enc_key *b_key, const v
typedef size_t (*dap_enc_gen_alice_shared_key) (struct dap_enc_key *a_key, const void *a_priv,
size_t b_pub_size, unsigned char *b_pub);
typedef int (*dap_enc_callback_gen_key_public_t ) (struct dap_enc_key *l_key, void * l_output);
typedef int (*dap_enc_callback_gen_key_public_t ) (struct dap_enc_key *a_key, void * a_output);
typedef void (*dap_enc_callback_ptr_t)(struct dap_enc_key *, void *);
typedef size_t (*dap_enc_callback_pptr_r_size_t)(struct dap_enc_key *, void **);
......@@ -171,6 +184,7 @@ typedef void (*dap_enc_callback_size_t)(struct dap_enc_key *, size_t);
typedef void (*dap_enc_callback_str_t)(struct dap_enc_key *, const char*);
typedef char* (*dap_enc_callback_r_str_t)(struct dap_enc_key *);
typedef size_t (*dap_enc_callback_calc_out_size)(const size_t);
typedef size_t (*dap_enc_get_allpbk_list) (struct dap_enc_key *a_key, const void *allpbk_list, const int allpbk_num);
typedef struct dap_enc_key {
size_t priv_key_data_size;
......@@ -187,6 +201,7 @@ typedef struct dap_enc_key {
dap_enc_callback_dataop_t dec;
dap_enc_callback_dataop_na_t enc_na;
dap_enc_callback_dataop_na_t dec_na;
dap_enc_callback_dataop_na_ext_t dec_na_ext;
dap_enc_callback_sign_op_t sign_get;
dap_enc_callback_sign_op_t sign_verify;
......@@ -194,6 +209,11 @@ typedef struct dap_enc_key {
dap_enc_gen_alice_shared_key gen_alice_shared_key;
dap_enc_gen_bob_shared_key gen_bob_shared_key;
void *pbkListdata;
size_t pbkListsize;
dap_enc_get_allpbk_list getallpbkList;
void * _inheritor; // WARNING! Inheritor must have only serealizeble/deserializeble data (copy)
size_t _inheritor_size;
} dap_enc_key_t;
......@@ -221,7 +241,7 @@ extern "C" {
int dap_enc_key_init(void);
void dap_enc_key_deinit(void);
const char *dap_enc_get_type_name(dap_enc_key_type_t a_key_type);
size_t dap_enc_key_get_enc_size(dap_enc_key_t * a_key, const size_t buf_in_size);
size_t dap_enc_key_get_dec_size(dap_enc_key_t * a_key, const size_t buf_in_size);
......@@ -229,7 +249,7 @@ uint8_t* dap_enc_key_serealize_sign(dap_enc_key_type_t a_key_type, uint8_t *a_si
uint8_t* dap_enc_key_deserealize_sign(dap_enc_key_type_t a_key_type, uint8_t *a_sign, size_t *a_sign_len);
uint8_t* dap_enc_key_serealize_priv_key(dap_enc_key_t *a_key, size_t *a_buflen_out);
uint8_t* dap_enc_key_serealize_pub_key(dap_enc_key_t *a_key, size_t *a_buflen_out);
int dap_enc_key_deserealize_priv_key(dap_enc_key_t *a_key, uint8_t *a_buf, size_t a_buflen);
int dap_enc_key_deserealize_priv_key(dap_enc_key_t *a_key, const uint8_t *a_buf, size_t a_buflen);
int dap_enc_key_deserealize_pub_key(dap_enc_key_t *a_key, const uint8_t *a_buf, size_t a_buflen);
dap_enc_key_serealize_t* dap_enc_key_serealize(dap_enc_key_t * key);
......
#ifndef DAP_ENC_RINGCT20_H
#define DAP_ENC_RINGCT20_H
#include "ringct20/ringct20_params.h"
#include "dap_enc_key.h"
size_t CRUTCH_gen_pbk_list(const ringct20_param_t *p, void **pbklist, const int pbknum);
void dap_enc_sig_ringct20_set_type(DAP_RINGCT20_SIGN_SECURITY type);
void dap_enc_sig_ringct20_key_new(struct dap_enc_key *key);
void dap_enc_sig_ringct20_key_new_generate(struct dap_enc_key * key, const void *kex_buf,
size_t kex_size, const void * seed, size_t seed_size,
size_t key_size);
size_t dap_enc_sig_ringct20_get_sign_with_pb_list(struct dap_enc_key * key, const void * msg,
const size_t msg_size, void * signature, const size_t signature_size);
size_t dap_enc_sig_ringct20_verify_sign_with_pbk_list(struct dap_enc_key * key, const void * msg,
const size_t msg_size, void * signature, const size_t signature_size, const void *pbkList_buf, const int wpbkList);
size_t dap_enc_sig_ringct20_get_sign(struct dap_enc_key * key,const void * msg,
const size_t msg_size, void * signature, const size_t signature_size);
size_t dap_enc_sig_ringct20_verify_sign(struct dap_enc_key * key,const void * msg,
const size_t msg_size, void * signature, const size_t signature_size);
void dap_enc_sig_ringct20_key_delete(struct dap_enc_key * key);
size_t dap_enc_ringct20_calc_signature_size(void);
uint8_t* dap_enc_ringct20_write_signature(ringct20_signature_t* a_sign, size_t *a_sign_out);
ringct20_signature_t* dap_enc_ringct20_read_signature(uint8_t *a_buf, size_t a_buflen);
uint8_t* dap_enc_ringct20_write_private_key(const ringct20_private_key_t* a_private_key, size_t *a_buflen_out);
uint8_t* dap_enc_ringct20_write_public_key(const ringct20_public_key_t* a_public_key, size_t *a_buflen_out);
ringct20_private_key_t* dap_enc_ringct20_read_private_key(const uint8_t *a_buf, size_t a_buflen);
ringct20_public_key_t* dap_enc_ringct20_read_public_key(const uint8_t *a_buf, size_t a_buflen);
#endif // DAP_ENC_RINGCT20_H
#ifndef _DAP_ENC_SALSA2012_H_
#define _DAP_ENC_SALSA2012_H_
#include <stddef.h>
#include "dap_enc_key.h"
#include "salsa2012/crypto_stream_salsa2012.h"
#ifdef __cplusplus
extern "C" {
#endif
void dap_enc_salsa2012_key_delete(struct dap_enc_key *a_key);
void dap_enc_salsa2012_key_generate(struct dap_enc_key * a_key, const void *kex_buf,
size_t kex_size, const void * seed, size_t seed_size, size_t key_size);
//------salsa2012---------
void dap_enc_salsa2012_key_new(struct dap_enc_key * a_key);
size_t dap_enc_salsa2012_calc_decode_size(const size_t size_in);
size_t dap_enc_salsa2012_calc_encode_size(const size_t size_in);
size_t dap_enc_salsa2012_decrypt(struct dap_enc_key * a_key, const void * a_in, size_t a_in_size, void ** a_out);
size_t dap_enc_salsa2012_encrypt(struct dap_enc_key * a_key, const void * a_in, size_t a_in_size, void ** a_out);
// Writes result ( out ) in already allocated buffer
size_t dap_enc_salsa2012_decrypt_fast(struct dap_enc_key * a_key, const void * a_in,
size_t a_in_size, void * buf_out, size_t buf_out_size);
// Writes result ( out ) in already allocated buffer
size_t dap_enc_salsa2012_encrypt_fast(struct dap_enc_key * a_key, const void * a_in,
size_t a_in_size, void * buf_out, size_t buf_out_size);
#ifdef __cplusplus
}
#endif
#endif
......@@ -26,6 +26,7 @@
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include <assert.h>
#include "dap_common.h"
#include "dap_hash_keccak.h"
......@@ -96,12 +97,12 @@ static inline bool dap_hash_fast_is_blank( dap_chain_hash_fast_t *a_hash )
DAP_STATIC_INLINE int dap_chain_hash_fast_to_str( dap_chain_hash_fast_t *a_hash, char *a_str, size_t a_str_max )
{
(void) a_str_max;
a_str[0] = '0';
a_str[1] = 'x';
a_str[ DAP_CHAIN_HASH_FAST_SIZE * 2 + 2 ] = 0;
dap_htoa64( (a_str + 2), a_hash->raw, DAP_CHAIN_HASH_FAST_SIZE );
return DAP_CHAIN_HASH_FAST_SIZE * 2 + 2;
assert(a_str_max >= (DAP_CHAIN_HASH_FAST_SIZE * 2 + 2));
a_str[0] = '0';
a_str[1] = 'x';
a_str[ DAP_CHAIN_HASH_FAST_SIZE * 2 + 2] = 0;
dap_htoa64((a_str + 2), a_hash->raw, DAP_CHAIN_HASH_FAST_SIZE);
return DAP_CHAIN_HASH_FAST_SIZE * 2 + 2;
}
static inline char *dap_chain_hash_fast_to_str_new(dap_chain_hash_fast_t * a_hash)
......
......@@ -31,23 +31,26 @@
#include "dap_pkey.h"
#include "dap_hash.h"
typedef union dap_sign_type{
enum {
SIG_TYPE_NULL = 0x0000,
SIG_TYPE_BLISS = 0x0001,
SIG_TYPE_DEFO = 0x0002, /// @brief key image for anonymous transaction
SIG_TYPE_TESLA = 0x0003, /// @brief
SIG_TYPE_PICNIC = 0x0101, /// @brief
SIG_TYPE_DILITHIUM = 0x0102, /// @brief
SIG_TYPE_MULTI = 0xffff /// @brief Has inside subset of different signatures and sign composed with all of them
} type: 16;
typedef enum {
SIG_TYPE_NULL = 0x0000,
SIG_TYPE_BLISS = 0x0001,
SIG_TYPE_DEFO = 0x0002, /// @brief key image for anonymous transaction
SIG_TYPE_TESLA = 0x0003, /// @brief
SIG_TYPE_PICNIC = 0x0101, /// @brief
SIG_TYPE_DILITHIUM = 0x0102, /// @brief
SIG_TYPE_MULTI_CHAINED = 0x0f00, /// @brief Has inside subset of different signatures and sign composed with all of them
SIG_TYPE_MULTI_COMBINED = 0x0f01 /// @brief Has inside subset of different public keys and sign composed with all of appropriate private keys
} dap_sign_type_enum_t;
typedef union dap_sign_type {
dap_sign_type_enum_t type: 16;
uint16_t raw;
} dap_sign_type_t;
typedef struct dap_sign_hdr{
typedef struct dap_sign_hdr {
dap_sign_type_t type; /// Signature type
uint8_t padding[2]; /// Padding for better aligmnent
uint16_t sign_size; /// Signature size
uint32_t sign_size; /// Signature size
uint32_t sign_pkey_size; /// Signature serialized public key size
} DAP_ALIGN_PACKED dap_sign_hdr_t;
......@@ -61,6 +64,42 @@ typedef struct dap_sign
uint8_t pkey_n_sign[]; /// @param sig @brief raw signature data
} DAP_ALIGN_PACKED dap_sign_t;
#define MULTI_SIGN_MAX_COUNT 255
typedef struct _dap_multi_sign_params_t {
dap_sign_type_t type; // Multi-signature type
uint8_t total_count; // Total key count
uint8_t sign_count; // Signatures count
uint8_t *key_seq; // Signing key sequence
dap_enc_key_t **keys; // Signing keys
} dap_multi_sign_params_t;
typedef struct _dap_multi_sign_meta_t {
uint32_t pkey_size; // Size of public key
uint32_t sign_size; // Size of signature
} DAP_ALIGN_PACKED dap_multi_sign_meta_t;
typedef struct _dap_multi_sign_keys_t {
uint8_t num;
dap_sign_type_t type;
} DAP_ALIGN_PACKED dap_multi_sign_keys_t;
typedef struct _dap_multi_sign_t {
/*** Hashed metadata ***/
dap_sign_type_t type; // Multi-signature type
uint8_t total_count; // Total key count
uint8_t sign_count; // Signatures count
dap_multi_sign_keys_t *key_seq; // Signing key sequence
/*** Unhashed metadata ***/
dap_multi_sign_meta_t *meta; // Sizes of keys and signatures
/*** Key hashes ***/
dap_chain_hash_fast_t *key_hashes; // Total key hashes
/*** Serialized public keys ***/
uint8_t *pub_keys; // Public keys for this signature
/*** Serialized signatures chain ***/
uint8_t *sign_data; // Signatures data
} DAP_ALIGN_PACKED dap_multi_sign_t;
#ifdef __cplusplus
extern "C" {
#endif
......@@ -89,6 +128,14 @@ dap_enc_key_t *dap_sign_to_enc_key(dap_sign_t * a_chain_sign);
const char * dap_sign_type_to_str(dap_sign_type_t a_chain_sign_type);
dap_sign_type_t dap_sign_type_from_str(const char * a_type_str);
uint8_t *dap_multi_sign_serialize(dap_multi_sign_t *a_sign, size_t *a_out_len);
dap_multi_sign_t *dap_multi_sign_deserialize(dap_sign_type_enum_t a_type, uint8_t *a_sign, size_t a_sign_len);
dap_multi_sign_params_t *dap_multi_sign_params_make(dap_sign_type_enum_t a_type, uint8_t a_total_count, uint8_t a_sign_count, dap_enc_key_t *a_key1, ...);
void dap_multi_sign_params_delete(dap_multi_sign_params_t *a_params);
dap_multi_sign_t *dap_multi_sign_create(dap_multi_sign_params_t *a_params, const void *a_data, const size_t a_data_size);
int dap_multi_sign_verify(dap_multi_sign_t *a_sign, const void *a_data, const size_t a_data_size);
void dap_multi_sign_delete(dap_multi_sign_t *a_sign);
#ifdef __cplusplus
}
#endif
include (src/defeo_scheme/defeo.pri)
include (src/iaes/iaes.pri)
include (src/oaes/oaes.pri)
include (src/blowfish/blowfish.pri)
include (src/GOST/GOST.pri)
include (src/salsa2012/salsa2012.pri)
include (src/blowfish/blowfish.pri)
include (src/msrln/msrln.pri)
include (src/rand/rand.pri)
include (src/sha3/sha3.pri)
......@@ -8,6 +12,7 @@ include (src/sig_bliss/sig_bliss.pri)
include (src/sig_picnic/sig_picnic.pri)
include (src/sig_tesla/sig_tesla.pri)
include (src/sig_dilithium/sig_dilithium.pri)
include (src/ringct20/ringct20.pri)
DEFINES += KeccakP1600timesN_excluded
......@@ -15,6 +20,8 @@ HEADERS += $$PWD/include/dap_enc.h \
$$PWD/include/dap_enc_base64.h \
$$PWD/include/dap_enc_iaes.h \
$$PWD/include/dap_enc_oaes.h \
$$PWD/include/dap_enc_bf.h \
$$PWD/include/dap_enc_GOST.h \
$$PWD/include/dap_enc_msrln.h \
$$PWD/include/dap_enc_key.h \
$$PWD/include/dap_enc_defeo.h \
......@@ -23,6 +30,7 @@ HEADERS += $$PWD/include/dap_enc.h \
$$PWD/include/dap_enc_tesla.h \
$$PWD/include/dap_enc_base58.h \
$$PWD/include/dap_enc_dilithium.h \
$$PWD/include/dap_enc_ringct20.h \
$$PWD/include/dap_crypto_common.h \
$$PWD/include/dap_cert.h \
$$PWD/include/dap_cert_file.h \
......@@ -39,6 +47,8 @@ SOURCES += $$PWD/src/dap_enc.c \
$$PWD/src/dap_enc_base64.c \
$$PWD/src/dap_enc_iaes.c \
$$PWD/src/dap_enc_oaes.c \
$$PWD/src/dap_enc_bf.c \
$$PWD/src/dap_enc_GOST.c \
$$PWD/src/dap_enc_msrln.c \
$$PWD/src/dap_enc_key.c \
$$PWD/src/dap_enc_defeo.c \
......@@ -47,6 +57,7 @@ SOURCES += $$PWD/src/dap_enc.c \
$$PWD/src/dap_enc_tesla.c \
$$PWD/src/dap_enc_base58.c \
$$PWD/src/dap_enc_dilithium.c \
$$PWD/src/dap_enc_ringct20.c \
$$PWD/src/dap_enc_ca.c \
$$PWD/src/dap_cert.c \
$$PWD/src/dap_cert_file.c \
......
/** @file
* @brief ""
*
* @copyright InfoTeCS. All rights reserved.
*/
#include <memory.h>
#include "28147_14.h"
#include "table.h"
/** @brief . */
static const unsigned char kPi[256] =
{
252, 238, 221, 17, 207, 110, 49, 22, 251, 196, 250, 218, 35, 197, 4, 77,
233, 119, 240, 219, 147, 46, 153, 186, 23, 54, 241, 187, 20, 205, 95, 193,
249, 24, 101, 90, 226, 92, 239, 33, 129, 28, 60, 66, 139, 1, 142, 79,
5, 132, 2, 174, 227, 106, 143, 160, 6, 11, 237, 152, 127, 212, 211, 31,
235, 52, 44, 81, 234, 200, 72, 171, 242, 42, 104, 162, 253, 58, 206, 204,
181, 112, 14, 86, 8, 12, 118, 18, 191, 114, 19, 71, 156, 183, 93, 135,
21, 161, 150, 41, 16, 123, 154, 199, 243, 145, 120, 111, 157, 158, 178, 177,
50, 117, 25, 61, 255, 53, 138, 126, 109, 84, 198, 128, 195, 189, 13, 87,
223, 245, 36, 169, 62, 168, 67, 201, 215, 121, 214, 246, 124, 34, 185, 3,
224, 15, 236, 222, 122, 148, 176, 188, 220, 232, 40, 80, 78, 51, 10, 74,
167, 151, 96, 115, 30, 0, 98, 68, 26, 184, 56, 130, 100, 159, 38, 65,
173, 69, 70, 146, 39, 94, 85, 47, 140, 163, 165, 125, 105, 213, 149, 59,
7, 88, 179, 64, 134, 172, 29, 247, 48, 55, 107, 228, 136, 217, 231, 137,
225, 27, 131, 73, 76, 63, 248, 254, 141, 83, 170, 144, 202, 216, 133, 97,
32, 113, 103, 164, 45, 43, 9, 91, 203, 155, 37, 208, 190, 229, 108, 82,
89, 166, 116, 210, 230, 244, 180, 192, 209, 102, 175, 194, 57, 75, 99, 182
};
/** @brief . */
static const unsigned char kReversePi[256] =
{
0xa5,0x2d,0x32,0x8f,0x0e,0x30,0x38,0xc0,0x54,0xe6,0x9e,0x39,0x55,0x7e,0x52,0x91,
0x64,0x03,0x57,0x5a,0x1c,0x60,0x07,0x18,0x21,0x72,0xa8,0xd1,0x29,0xc6,0xa4,0x3f,
0xe0,0x27,0x8d,0x0c,0x82,0xea,0xae,0xb4,0x9a,0x63,0x49,0xe5,0x42,0xe4,0x15,0xb7,
0xc8,0x06,0x70,0x9d,0x41,0x75,0x19,0xc9,0xaa,0xfc,0x4d,0xbf,0x2a,0x73,0x84,0xd5,
0xc3,0xaf,0x2b,0x86,0xa7,0xb1,0xb2,0x5b,0x46,0xd3,0x9f,0xfd,0xd4,0x0f,0x9c,0x2f,
0x9b,0x43,0xef,0xd9,0x79,0xb6,0x53,0x7f,0xc1,0xf0,0x23,0xe7,0x25,0x5e,0xb5,0x1e,
0xa2,0xdf,0xa6,0xfe,0xac,0x22,0xf9,0xe2,0x4a,0xbc,0x35,0xca,0xee,0x78,0x05,0x6b,
0x51,0xe1,0x59,0xa3,0xf2,0x71,0x56,0x11,0x6a,0x89,0x94,0x65,0x8c,0xbb,0x77,0x3c,
0x7b,0x28,0xab,0xd2,0x31,0xde,0xc4,0x5f,0xcc,0xcf,0x76,0x2c,0xb8,0xd8,0x2e,0x36,
0xdb,0x69,0xb3,0x14,0x95,0xbe,0x62,0xa1,0x3b,0x16,0x66,0xe9,0x5c,0x6c,0x6d,0xad,
0x37,0x61,0x4b,0xb9,0xe3,0xba,0xf1,0xa0,0x85,0x83,0xda,0x47,0xc5,0xb0,0x33,0xfa,
0x96,0x6f,0x6e,0xc2,0xf6,0x50,0xff,0x5d,0xa9,0x8e,0x17,0x1b,0x97,0x7d,0xec,0x58,
0xf7,0x1f,0xfb,0x7c,0x09,0x0d,0x7a,0x67,0x45,0x87,0xdc,0xe8,0x4f,0x1d,0x4e,0x04,
0xeb,0xf8,0xf3,0x3e,0x3d,0xbd,0x8a,0x88,0xdd,0xcd,0x0b,0x13,0x98,0x02,0x93,0x80,
0x90,0xd0,0x24,0x34,0xcb,0xed,0xf4,0xce,0x99,0x10,0x44,0x40,0x92,0x3a,0x01,0x26,
0x12,0x1a,0x48,0x68,0xf5,0x81,0x8b,0xc7,0xd6,0x20,0x0a,0x08,0x00,0x4c,0xd7,0x74
};
/** @brief l */
static const unsigned char kB[16] = {148, 32, 133, 16, 194, 192, 1, 251, 1, 192, 194, 16, 133, 32, 148, 1};
int DLL_IMPORT funcX(unsigned char* a, unsigned char* b, unsigned char* outdata, printout_byte_array print)
{
unsigned int i;
if(!a || !b || !outdata)
{
if(print)
print("funcX: internal error!", 0, 0);
return -1;
}
for(i = 0; i < 16; ++i)
{
outdata[i] = a[i] ^ b[i];
}
if(print)
{
print("funcX: a: ", a, 16);
print("funcX: b: ", b, 16);
print("funcX: result: ", outdata, 16);
}
return 0;
}
int DLL_IMPORT funcS(unsigned char* indata, unsigned char* outdata, printout_byte_array print)
{
size_t i = 0;
if(!indata || !outdata)
{
if(print)
print("funcS: internal error!", 0, 0);
return -1;
}
for(i = 0; i < 16; ++i)
{
outdata[i] = kPi[indata[i]];
}
if(print)
{
print("funcS: input: ", indata, 16);
print("funcS: output: ", outdata, 16);
}
return 0;
}
int DLL_IMPORT funcReverseS(unsigned char* indata, unsigned char* outdata, printout_byte_array print)
{
unsigned int i;
if(!indata || !outdata)
{
if(print)
print("funcReverseS: internal error!", 0, 0);
return -1;
}
for(i = 0; i < 16; ++i)
outdata[i] = kReversePi[indata[i]];
if(print)
{
print("funcReverseS: input: ", indata, 16);
print("funcReverseS: output: ", outdata, 16);
}
return 0;
}
int DLL_IMPORT funcR(unsigned char* indata, unsigned char* outdata, printout_byte_array print)
{
size_t i;
unsigned char sum = 0;
if(!indata || !outdata)
{
if(print)
print("funcR: internal error!", 0, 0);
return -1;
}
for(i = 0; i < 16; ++i)
{
sum ^= multTable[indata[i]*256 + kB[i]];
}
outdata[0] = sum;
memcpy(outdata+1, indata, 15);
if(print)
{
print("funcR: input: ", indata, 16);
print("funcR: output: ", outdata, 16);
}
return 0;
}
int DLL_IMPORT funcReverseR(unsigned char* indata, unsigned char* outdata, printout_byte_array print)
{
unsigned char tmp[16];
unsigned char sum = 0;
unsigned int i;
if(!indata || !outdata)
{
if(print)
print("funcReverseR: internal error!", 0, 0);
return -1;
}
memcpy(tmp, indata+1, 15);
tmp[15] = indata[0];
for(i = 0; i < 16; ++i)
{
sum ^= multTable[tmp[i]*256 + kB[i]];
}
memcpy(outdata, tmp, 15);
outdata[15] = sum;
if(print)
{
print("funcReverseR: input: ", indata, 16);
print("funcReverseR: output: ", outdata, 16);
}
return 0;
}
int DLL_IMPORT funcL(unsigned char* indata, unsigned char* outdata, printout_byte_array print)
{
unsigned char tmp[16];
int i = 0;
if(!indata || !outdata)
{
if(print)
print("funcL: internal error!", 0, 0);
return -1;
}
memcpy(tmp, indata, 16);
for(i = 0; i < 16; ++i)
{
funcR(tmp, outdata, print);
memcpy(tmp, outdata, 16);
}
if(print)
{
print("funcL: input: ", indata, 16);
print("funcL: output: ", outdata, 16);
}
return 0;
}
int DLL_IMPORT funcReverseL(unsigned char* indata, unsigned char* outdata, printout_byte_array print)
{
unsigned char tmp[16];
unsigned int i;
if(!indata || !outdata)
{
if(print)
print("funcReverseL: internal error!", 0, 0);
return -1;
}
memcpy(tmp, indata, 16);
for(i = 0; i < 16; ++i)
{
funcReverseR(tmp, outdata, print);
memcpy(tmp, outdata, 16);
}
if(print)
{
print("funcReverseL: input: ", indata, 16);
print("funcReverseL: output: ", outdata, 16);
}
return 0;
}
int DLL_IMPORT funcLSX(unsigned char* a, unsigned char* b, unsigned char* outdata, printout_byte_array print)
{
unsigned char temp1[16];
unsigned char temp2[16];
if(!a || !b || !outdata)
{
if(print)
print("funcLSX: internal error!", 0, 0);
return -1;
}
funcX(a, b, temp1, print);
funcS(temp1, temp2, print);
funcL(temp2, outdata, print);
if(print)
{
print("funcLSX: a: ", a, 16);
print("funcLSX: b: ", b, 16);
print("funcLSX: output: ", outdata, 16);
}
return 0;
}
int DLL_IMPORT funcReverseLSX(unsigned char* a, unsigned char* b, unsigned char* outdata, printout_byte_array print)
{
unsigned char temp1[16];
unsigned char temp2[16];
if(!a || !b || !outdata)
{
if(print)
print("funcReverseLSX: internal error!", 0, 0);
return -1;
}
funcX(a, b, temp1, print);
funcReverseL(temp1, temp2, print);
funcReverseS(temp2, outdata, print);
if(print)
{
print("funcReverseLSX: a: ", a, 16);
print("funcReverseLSX: b: ", b, 16);
print("funcReverseLSX: output: ", outdata, 16);
}
return 0;
}
int DLL_IMPORT funcF(unsigned char* inputKey, unsigned char* inputKeySecond, unsigned char* iterationConst, unsigned char* outputKey, unsigned char* outputKeySecond, printout_byte_array print)
{
unsigned char temp1[16];
unsigned char temp2[16];
if(!inputKey || !inputKeySecond || !iterationConst || !outputKey || !outputKeySecond)
{
if(print)
print("funcF: internal error!", 0, 0);
return -1;
}
funcLSX(inputKey, iterationConst, temp1, print);
funcX(temp1, inputKeySecond, temp2, print);
memcpy(outputKeySecond, inputKey, 16);
memcpy(outputKey, temp2, 16);
if(print)
{
print("funcF: input key: ", inputKey, 16);
print("funcF: input key: ", inputKeySecond, 16);
print("funcF: iterration const: ", iterationConst, 16);
print("funcF: output key: ", outputKey, 16);
print("funcF: output key: ", outputKeySecond, 16);
}
return 0;
}
int DLL_IMPORT funcC(unsigned char number, unsigned char* output, printout_byte_array print)
{
unsigned char tempI[16];
if(!output)
{
if(print)
print("funcC: internal error!", 0, 0);
return -1;
}
memset( tempI, 0, 15 );
tempI[15] = number;
funcL(tempI, output, print);
return 0;
}
int DLL_IMPORT ExpandKey(unsigned char* masterKey, unsigned char* keys, printout_byte_array print)
{
unsigned char C[16];
unsigned char temp1[16];
unsigned char temp2[16];
unsigned char j, i;
if( !masterKey || !keys)
{
if(print)
print("ExpandKey: internal error!", 0, 0);
return -1;
}
memcpy(keys, masterKey, 16);
memcpy(keys + 16, masterKey + 16, 16);
if(print)
{
print("ExpandKey: master key: ", masterKey, 16);
print("ExpandKey: output key: ", keys, 16);
print("ExpandKey: output key: ", keys + 16, 16);
}
for(j = 0; j < 4; ++j)
{
memcpy(temp1, keys + j * 2 * 16, 16);
memcpy(temp2, keys + (j * 2 + 1) * 16, 16);
for( i = 1; i < 8; ++i )
{
funcC(j*8+i, C, print);
funcF(temp1, temp2, C, temp1, temp2, print);
}
funcC(j*8+8, C, print);
funcF(temp1, temp2, C, temp1, temp2, print);
memcpy(keys + (j * 2 + 2) * 16, temp1, 16);
memcpy(keys + (j * 2 + 3) * 16, temp2, 16);
if(print)
{
print("ExpandKey: output key: ", keys + (j * 2 + 2) * 16, 16);
print("ExpandKey: output key: ", keys + (j * 2 + 3) * 16, 16);
}
}
return 0;
}
int DLL_IMPORT Encrypt_14(unsigned char* plainText, unsigned char* chipherText, unsigned char* keys, printout_byte_array print, printout_uint_array print_uint)
{
unsigned char xTemp[16];
unsigned char yTemp[16];
int i;
(void)print_uint;
if(!plainText || !chipherText || !keys)
{
if(print)
print("Encrypt_14: internal error!", 0, 0);
return -1;
}
memcpy(xTemp, plainText, 16);
for(i = 0; i < 9; ++i)
{
funcLSX(xTemp, keys + 16*i, yTemp, print);
memcpy(xTemp, yTemp, 16);
}
funcX(yTemp, keys+9*16, chipherText, print);
if(print)
{
for(i = 0; i < 10; ++i)
{
print("Encrypt_14: key: ", keys, 16);
keys += 16;
}
print("Encrypt_14: plain text: ", plainText, 16);
print("Encrypt_14: chipher text: ", chipherText, 16);
}
return 0;
}
int DLL_IMPORT Decrypt_14(unsigned char* chipherText, unsigned char* plainText, unsigned char* keys, printout_byte_array print, printout_uint_array print_uint)
{
unsigned char xTemp[16];
unsigned char yTemp[16];
int i;
(void)print_uint;
if(!plainText || !chipherText || !keys)
{
if(print)
print("Decrypt_14: internal error!", 0, 0);
return -1;
}
memcpy(xTemp, chipherText, 16);
for(i = 0; i < 9; ++i)
{
funcReverseLSX(xTemp, keys+(9-i)*16, yTemp, print);
memcpy(xTemp, yTemp, 16);
}
funcX(yTemp, keys, plainText, print);
if(print)
{
for(i = 0; i < 10; ++i)
{
print("Decrypt_14: key: ", keys, 16);
keys += 16;
}
print("Decrypt_14: chipher text : ", chipherText, 16);
print("Decrypt_14: plain text: ", plainText, 16);
}
return 0;
}
\ No newline at end of file
/** @file
* @brief ""
*
* @copyright InfoTeCS. All rights reserved.
*/
#ifndef C_28147_14_H
#define C_28147_14_H
#include "dll_import.h"
#include "callback_print.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @brief X
*
* @param[in] a
* @param[in] b
* @param[out] outdata
* @param[in] print
* @return 0
* @return -1
*/
int DLL_IMPORT funcX(unsigned char* a, unsigned char* b, unsigned char* outdata, printout_byte_array print);
/** @brief S
*
* @param[in] indata
* @param[out] outdata
* @param[in] print
* @return 0
* @return -1
*/
int DLL_IMPORT funcS(unsigned char* indata, unsigned char* outdata, printout_byte_array print);
/** @brief S
*
* @param[in] indata
* @param[out] outdata
* @param[in] print
* @return 0
* @return -1
*/
int DLL_IMPORT funcReverseS(unsigned char* indata, unsigned char* outdata, printout_byte_array print);
/** @brief R
*
* @param[in] indata
* @param[out] outdata
* @param[in] print
* @return 0
* @return -1
*/
int DLL_IMPORT funcR(unsigned char* indata, unsigned char* outdata, printout_byte_array print);
/** @brief R
*
* @param[in] indata
* @param[out] outdata
* @param[in] print
* @return 0
* @return -1
*/
int DLL_IMPORT funcReverseR(unsigned char* indata, unsigned char* outdata, printout_byte_array print);
/** @brief L
*
* @param[in] indata
* @param[out] outdata
* @param[in] print
* @return 0
* @return -1
*/
int DLL_IMPORT funcL(unsigned char* indata, unsigned char* outdata, printout_byte_array print);
/** @brief L
*
* @param[in] indata
* @param[out] outdata
* @param[in] print
* @return 0
* @return -1
*/
int DLL_IMPORT funcReverseL(unsigned char* indata, unsigned char* outdata, printout_byte_array print);
/** @brief LSX
*
* @param[in] a
* @param[in] b
* @param[out] outdata
* @param[in] print
* @return 0
* @return -1
*/
int DLL_IMPORT funcLSX(unsigned char* a, unsigned char* b, unsigned char* outdata, printout_byte_array print);
/** @brief LSX
*
* @param[in] a
* @param[in] b
* @param[out] outdata
* @param[in] print
* @return 0
* @return -1
*/
int DLL_IMPORT funcReverseLSX(unsigned char* a, unsigned char* b, unsigned char* outdata, printout_byte_array print);
/** @brief F
*
* @param[in] inputKey
* @param[in] inputKeySecond
* @param[in] iterationConst
* @param[out] outputKey
* @param[out] outputKeySecond
* @param[in] print
* @return 0
* @return -1
*/
int DLL_IMPORT funcF(unsigned char* inputKey, unsigned char* inputKeySecond, unsigned char* iterationConst, unsigned char* outputKey, unsigned char* outputKeySecond, printout_byte_array print);
/** @brief
*
* @param[in] number
* @param[out] output
* @param[in] print
* @return 0
* @return -1
*/
int DLL_IMPORT funcC(unsigned char number, unsigned char* output, printout_byte_array print);
/** @brief
*
* @param[in] masterKey
* @param[out] keys
* @param[in] print
* @return 0
* @return -1
*/
int DLL_IMPORT ExpandKey(unsigned char* masterKey, unsigned char* keys, printout_byte_array print);
/** @brief
*
* @param[in] plainText
* @param[out] chipherText
* @param[in] keys
* @param[in] print
* @param[in] print_uint
* @return 0
* @return -1
*/
int DLL_IMPORT Encrypt_14(unsigned char* plainText, unsigned char* chipherText, unsigned char* keys, printout_byte_array print, printout_uint_array print_uint);
/** @brief
*
* @param[in] chipherText
* @param[out] plainText
* @param[in] keys
* @param[in] print
* @param[in] print_uint
* @return 0
* @return -1
*/
int DLL_IMPORT Decrypt_14(unsigned char* chipherText, unsigned char* plainText, unsigned char* keys, printout_byte_array print, printout_uint_array print_uint);
#ifdef __cplusplus
}
#endif
#endif
/** @file
* @brief 28147-89
*
* @copyright InfoTeCS. All rights reserved.
*/
#include "28147_89.h"
/** @brief int32
*
* @param[in] input 4
* @return int32
*/
static unsigned int uint8ToUint32(unsigned char* input)
{
unsigned int r = ( (input[3]) | (input[2]<<8) | (input[1]<<16) | (input[0]<<24));
return r;
}
/** @brief int32
*
* @param[in] input int32
* @param[out] output 4
*/
static void uint32ToUint8(unsigned int input, unsigned char* output)
{
int i;
for(i = 0; i < 4; ++i)
{
output[3-i] = ( ( input >> (8*i) ) & 0x000000ff );
}
}
/** @brief id-tc26-gost-28147-param-Z OID: 1.2.643.7.1.2.5.1.1 */
unsigned char p[8][16] =
{
{0xc, 0x4, 0x6, 0x2, 0xa, 0x5, 0xb, 0x9, 0xe, 0x8, 0xd, 0x7, 0x0, 0x3, 0xf, 0x1},
{0x6, 0x8, 0x2, 0x3, 0x9, 0xa, 0x5, 0xc, 0x1, 0xe, 0x4, 0x7, 0xb, 0xd, 0x0, 0xf},
{0xb, 0x3, 0x5, 0x8, 0x2, 0xf, 0xa, 0xd, 0xe, 0x1, 0x7, 0x4, 0xc, 0x9, 0x6, 0x0},
{0xc, 0x8, 0x2, 0x1, 0xd, 0x4, 0xf, 0x6, 0x7, 0x0, 0xa, 0x5, 0x3, 0xe, 0x9, 0xb},
{0x7, 0xf, 0x5, 0xa, 0x8, 0x1, 0x6, 0xd, 0x0, 0x9, 0x3, 0xe, 0xb, 0x4, 0x2, 0xc},
{0x5, 0xd, 0xf, 0x6, 0x9, 0x2, 0xc, 0xa, 0xb, 0x7, 0x8, 0x1, 0x4, 0x3, 0xe, 0x0},
{0x8, 0xe, 0x2, 0x5, 0x6, 0x9, 0x1, 0xc, 0xf, 0x4, 0xb, 0x0, 0xd, 0xa, 0x3, 0x7},
{0x1, 0x7, 0xe, 0xd, 0x0, 0x5, 0x8, 0x3, 0x4, 0xf, 0xa, 0x6, 0x9, 0xc, 0xb, 0x2}
};
/** @brief */
unsigned char kEncRoundKey[32] =
{
0, 4, 8, 12, 16, 20, 24, 28, 0, 4, 8, 12, 16, 20, 24, 28, 0, 4, 8, 12, 16, 20, 24, 28, 28, 24, 20, 16, 12, 8, 4, 0
};
/** @brief */
unsigned char kDecRoundKey[32] =
{
0, 4, 8, 12, 16, 20, 24, 28, 28, 24, 20, 16, 12, 8, 4, 0, 28, 24, 20, 16, 12, 8, 4, 0, 28, 24, 20, 16, 12, 8, 4, 0
};
unsigned int DLL_IMPORT funcT(unsigned int a, printout_uint_array print)
{
unsigned int res = 0;
res ^= p[ 0 ][ a & 0x0000000f ];
res ^= ( p[ 1 ][ ( ( a & 0x000000f0 ) >> 4 ) ] << 4 );
res ^= ( p[ 2 ][ ( ( a & 0x00000f00 ) >> 8 ) ] << 8 );
res ^= ( p[ 3 ][ ( ( a & 0x0000f000 ) >> 12 ) ] << 12 );
res ^= ( p[ 4 ][ ( ( a & 0x000f0000 ) >> 16 ) ] << 16 );
res ^= ( p[ 5 ][ ( ( a & 0x00f00000 ) >> 20 ) ] << 20 );
res ^= ( p[ 6 ][ ( ( a & 0x0f000000 ) >> 24 ) ] << 24 );
res ^= ( p[ 7 ][ ( ( a & 0xf0000000 ) >> 28 ) ] << 28 );
if(print)
{
print("funcT: a: ", &a, 1);
print("funcT: output: ", &res, 1);
}
return res;
}
unsigned int DLL_IMPORT funcG(unsigned int a, unsigned int k, printout_uint_array print)
{
unsigned int c = a + k;
unsigned int tmp = funcT(c, print);
unsigned int r = (tmp<<11) | (tmp >> 21);
if(print)
{
print("funcG: a: ", &a, 1);
print("funcG: k: ", &k, 1);
print("funcG: output: ", &r, 1);
}
return r;
}
void DLL_IMPORT Round(unsigned int* a1, unsigned int* a0, unsigned int k, printout_uint_array print)
{
unsigned int a;
unsigned int tmp;
if(print)
{
print("Round: input a1: ", a1, 1);
print("Round: input a0: ", a0, 1);
print("Round: k: ", &k, 1);
}
a = *a0;
tmp = funcG(*a0, k, print);
*a0 = *a1 ^ tmp;
*a1 = a;
if(print)
{
print("Round: output a1: ", a1, 1);
print("Round: output a0: ", a0, 1);
}
}
void DLL_IMPORT RoundShtrih(unsigned int* a1, unsigned int* a0, unsigned int k, printout_uint_array print)
{
unsigned int tmp;
if(print)
{
print("RoundShtrih: input a1: ", a1, 1);
print("RoundShtrih: input a0: ", a0, 1);
print("RoundShtrih: k: ", &k, 1);
}
tmp = funcG(*a0, k, print);
*a1 ^= tmp;
if(print)
{
print("RoundShtrih: output a1: ", a1, 1);
print("RoundShtrih: output a0: ", a0, 1);
}
}
int DLL_IMPORT CryptBlock(unsigned char* input, unsigned char* output, unsigned char* key, unsigned char* keyIndex, printout_uint_array print)
{
unsigned int a1 = uint8ToUint32(input);
unsigned int a0 = uint8ToUint32(input + 4);
int i;
if(print)
{
print("CryptBlock: input a1:", &a1, 1);
print("CryptBlock: input a0:", &a0, 1);
}
for(i = 0; i < 31; ++i)
{
Round(&a1, &a0, uint8ToUint32(key + keyIndex[i]), print);
}
RoundShtrih(&a1, &a0, uint8ToUint32(key + keyIndex[31]), print);
if(print)
{
print("CryptBlock: output a1:", &a1, 1);
print("CryptBlock: output a0:", &a0, 1);
}
uint32ToUint8(a1, output);
uint32ToUint8(a0, output+4);
return 0;
}
int DLL_IMPORT EncryptBlock(unsigned char* input, unsigned char* output, unsigned char* key, printout_uint_array print)
{
return CryptBlock(input, output, key, kEncRoundKey, print);
}
int DLL_IMPORT DecryptBlock(unsigned char* input, unsigned char* output, unsigned char* key, printout_uint_array print)
{
return CryptBlock(input, output, key, kDecRoundKey, print);
}
int DLL_IMPORT Encrypt_89(unsigned char* input, unsigned char* output, unsigned char* key, printout_byte_array print, printout_uint_array print_uint)
{
if( !input || !output || !key )
{
if(print)
print("Encrypt_89: internal error!", 0, 0);
return -1;
}
if(EncryptBlock(input, output, key, print_uint))
return -1;
if(print)
{
print("Encrypt_89: plain text: ", input, 8);
print("Encrypt_89: chipher text: ", output, 8);
}
return 0;
}
int DLL_IMPORT Decrypt_89(unsigned char* input, unsigned char* output, unsigned char* key, printout_byte_array print, printout_uint_array print_uint)
{
if( !input || !output || !key )
{
if(print)
print("Decrypt_89: internal error!", 0, 0);
return -1;
}
if(DecryptBlock(input, output, key, print_uint))
return -1;
if(print)
{
print("Encrypt_89: chipher text: ", input, 8);
print("Encrypt_89: plain text: ", output, 8);
}
return 0;
}
/** @file
* @brief "28147-89"
*
* @copyright InfoTeCS. All rights reserved.
*/
#ifndef C_28147_89_H
#define C_28147_89_H
#include "dll_import.h"
#include "callback_print.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @brief
*
* @param[in] a
* @param[in] print
* @return
*/
unsigned int DLL_IMPORT funcT(unsigned int a, printout_uint_array print);
/** @brief g
*
* @param[in] a
* @param[in] k
* @param[in] print
* @return
*/
unsigned int DLL_IMPORT funcG(unsigned int a, unsigned int k, printout_uint_array print);
/** @brief G
*
* @param[out] a1 ,
* @param[out] a0 ,
* @param[in] k
* @param[in] print
*/
void DLL_IMPORT Round(unsigned int* a1, unsigned int* a0, unsigned int k, printout_uint_array print);
/** @brief G ( 1 0 )
*
* @param[out] a1 ,
* @param[out] a0 ,
* @param[in] k
* @param[in] print
*/
void DLL_IMPORT RoundShtrih(unsigned int *a1, unsigned int *a0, unsigned int k, printout_uint_array print);
/** @brief
*
* @param[in] input -
* @param[out] output -
* @param[in] key
* @param[in] keySequence
* @param[in] print
* @return 0
* @return -1
*/
int DLL_IMPORT CryptBlock(unsigned char* input, unsigned char* output, unsigned char* key, unsigned char* keySequence, printout_uint_array print);
/** @brief
*
* @param[in] input -
* @param[out] output -
* @param[in] key
* @param[in] print
* @return 0
* @return -1
*/
int DLL_IMPORT EncryptBlock(unsigned char* input, unsigned char* output, unsigned char* key, printout_uint_array print);
/** @brief
*
* @param[in] input -
* @param[out] output -
* @param[in] key
* @param[in] print
* @return 0
* @return -1
*/
int DLL_IMPORT DecryptBlock(unsigned char* input, unsigned char* output, unsigned char* key, printout_uint_array print);
/** @brief
*
* @param[in] input -
* @param[out] output -
* @param[in] key
* @param[in] print
* @param[in] print_uint
* @return 0
* @return -1
*/
int DLL_IMPORT Encrypt_89(unsigned char* input, unsigned char* output, unsigned char* key, printout_byte_array print, printout_uint_array print_uint);
/** @brief
*
* @param[in] input -
* @param[out] output -
* @param[in] key
* @param[in] print
* @param[in] print_uint
* @return 0
* @return -1
*/
int DLL_IMPORT Decrypt_89(unsigned char* input, unsigned char* output, unsigned char* key, printout_byte_array print, printout_uint_array print_uint);
#ifdef __cplusplus
}
#endif
#endif
INCLUDEPATH += $$PWD
HEADERS += $$PWD/28147_14.h \
$$PWD/28147_89.h \
$$PWD/callback_print.h \
$$PWD/dll_import.h \
$$PWD/print_data.h \
$$PWD/table.h \
$$PWD/test_data.inc \
$$PWD/block_cipher.h
SOURCES += $$PWD/28147_14.c \
$$PWD/28147_89.c \
$$PWD/block_cipher.c \
$$PWD/print_data.c \
$$PWD/testgost.c
/** @file
* @brief
*
* @copyright InfoTeCS. All rights reserved.
*/
#include <stdio.h>
#include <memory.h>
#include <malloc.h>
#include <stdlib.h>
#include "28147_14.h"
#include "28147_89.h"
#include "block_chipher.h"
/** @brief */
#define INFOTECS_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]
/** @brief "" */
#define textLen14 sizeof(kSeltTestGost14PlainText)/sizeof(kSeltTestGost14PlainText[0])
/** @brief 28147-89 */
#define textLen89 sizeof(kSeltTestGost89PlainText)/sizeof(kSeltTestGost89PlainText[0])
/** @brief "" */
const unsigned char kAlg14 = 1;
/** @brief 28147-89 */
const unsigned char kAlg89 = 2;
/** @brief */
typedef int (DLL_IMPORT *pEncrypt)(unsigned char* plainText, unsigned char* chipherText, unsigned char* keys, printout_byte_array print, printout_uint_array print_uint);
/** @brief */
typedef int (DLL_IMPORT *pDecrypt)(unsigned char* chipherText, unsigned char* plainText, unsigned char* keys, printout_byte_array print, printout_uint_array print_uint);
/** @brief ECB */
static int SelfTestGost14Ecb();
/** @brief ECB */
static int SelfTestGost89Ecb();
/** @brief CTR */
static int SelfTestGost14Ctr();
/** @brief CTR */
static int SelfTestGost89Ctr();
/** @brief OFB */
static int SelfTestGost14Ofb();
/** @brief OFB */
static int SelfTestGost89Ofb();
/** @brief CBC */
static int SelfTestGost14Cbc();
/** @brief CBC */
static int SelfTestGost89Cbc();
/** @brief CFB */
static int SelfTestGost14Cfb();
/** @brief CFB */
static int SelfTestGost89Cfb();
/** @brief */
static int SelfTestGost14Imit();
/** @brief */
static int SelfTestGost89Imit();
/** @brief 1 */
static void ShifttLeftOne(unsigned char *r, size_t length);
/** @brief ECB */
typedef struct
{
unsigned char Alg; /**< */
unsigned char* Keys; /**< */
unsigned int BlockLen; /**< */
printout_byte_array PrintByteArray; /**< */
printout_uint_array PrintUIntArray; /**< */
pEncrypt EncryptFunc; /**< */
pDecrypt DecryptFunc; /**< */
} Context_ecb;
/** @brief CTR */
typedef struct
{
unsigned char Alg; /**< */
unsigned char* Counter; /**< */
unsigned char* Keys; /**< */
size_t S; /**< */
size_t BlockLen; /**< */
printout_byte_array PrintByteArray; /**< */
printout_uint_array PrintUIntArray; /**< */
pEncrypt EncryptFunc; /**< */
unsigned char *tmpblock; /**< */
} Context_ctr;
/** @brief OFB */
typedef struct
{
unsigned char Alg; /**< */
unsigned char* IV; /**< */
unsigned char* Keys; /**< */
size_t M; /**< */
size_t S; /**< S */
size_t BlockLen; /**< */
printout_byte_array PrintByteArray; /**< */
printout_uint_array PrintUIntArray; /**< */
pEncrypt EncryptFunc; /**< */
pDecrypt DecryptFunc; /**< */
unsigned char *tmpblock; /**< */
unsigned char* nextIV; /**< */
} Context_ofb;
/** @brief CFB */
typedef struct
{
unsigned char Alg; /**< */
unsigned char* IV; /**< */
unsigned char* Keys; /**< */
size_t M; /**< */
size_t S; /**< S */
size_t BlockLen; /**< */
printout_byte_array PrintByteArray; /**< */
printout_uint_array PrintUIntArray; /**< */
pEncrypt EncryptFunc; /**< */
pDecrypt DecryptFunc; /**< */
unsigned char *tmpblock; /**< */
unsigned char* nextIV; /**< */
} Context_cfb;
/** @brief CBC */
typedef struct
{
unsigned char Alg; /**< */
unsigned char* IV; /**< */
unsigned char* Keys; /**< */
size_t BlockLen; /**< */
size_t M; /**< */
printout_byte_array PrintByteArray; /**< */
printout_uint_array PrintUIntArray; /**< */
pEncrypt EncryptFunc; /**< */
pDecrypt DecryptFunc; /**< */
unsigned char* nextIV; /**< */
unsigned char* tempIV; /**< */
unsigned char *tmpblock; /**< */
} Context_cbc;
/** @brief */
typedef struct
{
unsigned char Alg; /**< */
unsigned char* Keys; /**< */
unsigned char* K1; /**< K1 */
unsigned char* K2; /**< K2 */
unsigned char* B; /**< B */
unsigned char* R; /**< R */
unsigned char* C; /**< C */
unsigned char* LastBlock; /**< */
size_t S; /**< S */
size_t BlockLen; /**< */
size_t LastBlockSize; /**< */
int isFistBlock; /**< */
printout_byte_array PrintByteArray; /**< */
printout_uint_array PrintUIntArray; /**< */
pEncrypt EncryptFunc; /**< */
unsigned char *tmpblock; /**< */
unsigned char *resimit; /**< */
} Context_imit;
static int init_ecb_14_impl(unsigned char *key, void* ctx, printout_byte_array print, printout_uint_array print_uint)
{
Context_ecb* context = 0;
INFOTECS_ASSERT(sizeof(Context_ecb)<=kEcb14ContextLen);
if(!ctx || !key)
return -1;
context = (Context_ecb*)ctx;
context->Alg = kAlg14;
context->EncryptFunc = Encrypt_14;
context->DecryptFunc = Decrypt_14;
context->BlockLen = kBlockLen14;
context->PrintByteArray = print;
context->PrintUIntArray = print_uint;
context->Keys = (unsigned char*)malloc(10 * kBlockLen14);
if( !context->Keys )
return -1;
memset(context->Keys, 0, 10 * kBlockLen14);
ExpandKey(key, context->Keys, print);
return 0;
}
int DLL_IMPORT init_ecb_14(unsigned char *key, void* ctx, printout_byte_array print, printout_uint_array print_uint)
{
if(SelfTestGost14Ecb())
return -1;
return init_ecb_14_impl(key, ctx, print, print_uint);
}
static int init_ecb_89_impl(unsigned char *key, void* ctx, printout_byte_array print, printout_uint_array print_uint)
{
Context_ecb* context;
INFOTECS_ASSERT(sizeof(Context_ecb)<=kEcb89ContextLen);
if(!ctx || !key)
return -1;
context = (Context_ecb*)ctx;
context->Alg = kAlg89;
context->PrintByteArray = print;
context->PrintUIntArray = print_uint;
context->EncryptFunc = Encrypt_89;
context->DecryptFunc = Decrypt_89;
context->BlockLen = kBlockLen89;
context->Keys = (unsigned char*)malloc(kKeyLen89);
if( !context->Keys )
return -1;
memcpy(context->Keys, key, kKeyLen89);
return 0;
}
int DLL_IMPORT init_ecb_89(unsigned char *key, void* ctx, printout_byte_array print, printout_uint_array print_uint)
{
if(SelfTestGost89Ecb())
return -1;
return init_ecb_89_impl(key, ctx, print, print_uint);
}
void DLL_IMPORT free_ecb(void* ctx)
{
Context_ecb* context;
if(!ctx)
return;
context = (Context_ecb*)(ctx);
if(context->Keys)
{
free(context->Keys);
context->Keys = 0;
}
}
static int init_cbc_14_impl(unsigned char *key, void* ctx, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint)
{
Context_cbc* context;
INFOTECS_ASSERT(sizeof(Context_cbc)<=kCbc14ContextLen);
if(!ctx || !key || !iv || (ivLength % kBlockLen14))
return -1;
context = (Context_cbc*)ctx;
context->Alg = kAlg14;
context->PrintByteArray = print;
context->PrintUIntArray = print_uint;
context->EncryptFunc = Encrypt_14;
context->DecryptFunc = Decrypt_14;
context->BlockLen = kBlockLen14;
context->M = ivLength;
context->IV = (unsigned char*)malloc(ivLength);
context->Keys = (unsigned char*)malloc(10 * kBlockLen14);
context->tempIV = (unsigned char*)malloc(context->M);
context->nextIV = (unsigned char*)malloc(context->M);
context->tmpblock = (unsigned char *)malloc(kBlockLen14);
if( !context->IV || !context->Keys || !context->tempIV || !context->nextIV || !context->tmpblock )
return -1;
memcpy(context->IV, iv, ivLength);
memset(context->Keys, 0, 10 * kBlockLen14);
ExpandKey(key, context->Keys, print);
return 0;
}
int DLL_IMPORT init_cbc_14(unsigned char *key, void* ctx, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint)
{
if(SelfTestGost14Cbc())
return -1;
return init_cbc_14_impl(key, ctx, iv, ivLength, print, print_uint);
}
static int init_cbc_89_impl(unsigned char *key, void* ctx, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint)
{
Context_cbc* context;
INFOTECS_ASSERT(sizeof(Context_cbc)<=kCbc89ContextLen);
if(!ctx || !key || !iv || (ivLength % kBlockLen89))
return -1;
context = (Context_cbc*)ctx;
context->Alg = kAlg89;
context->PrintByteArray = print;
context->PrintUIntArray = print_uint;
context->EncryptFunc = Encrypt_89;
context->DecryptFunc = Decrypt_89;
context->BlockLen = kBlockLen89;
context->M = ivLength;
context->IV = (unsigned char*)malloc(ivLength);
context->Keys = (unsigned char*)malloc(kKeyLen89);
context->tempIV = (unsigned char*)malloc(context->M);
context->nextIV = (unsigned char*)malloc(context->M);
context->tmpblock = (unsigned char *)malloc(kBlockLen89);
if( !context->IV || !context->Keys || !context->tempIV || !context->nextIV || !context->tmpblock )
return -1;
memcpy(context->IV, iv, ivLength);
memcpy(context->Keys, key, kKeyLen89);
return 0;
}
int DLL_IMPORT init_cbc_89(unsigned char *key, void* ctx, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint)
{
if(SelfTestGost89Cbc())
return -1;
return init_cbc_89_impl(key, ctx, iv, ivLength, print, print_uint);
}
void DLL_IMPORT free_cbc(void* ctx)
{
Context_cbc* context;
if(!ctx)
return;
context = (Context_cbc*)ctx;
if(context->Keys)
{
free(context->Keys);
context->Keys = 0;
}
if(context->IV)
{
free(context->IV);
context->IV = 0;
}
if(context->tempIV)
{
free(context->tempIV);
context->tempIV = 0;
}
if(context->nextIV)
{
free(context->nextIV);
context->nextIV = 0;
}
if(context->tmpblock)
{
free(context->tmpblock);
context->tmpblock = 0;
}
}
static int init_ctr_14_impl(unsigned char* key, unsigned char *iv, size_t s, void *ctx, printout_byte_array print, printout_uint_array print_uint)
{
Context_ctr* context;
INFOTECS_ASSERT(sizeof(Context_ctr)<=kCtr14ContextLen);
if(!ctx || !key || s > kBlockLen14)
return -1;
context = (Context_ctr*)ctx;
context->Alg = kAlg14;
context->PrintByteArray = print;
context->PrintUIntArray = print_uint;
context->EncryptFunc = Encrypt_14;
context->BlockLen = kBlockLen14;
context->S = s;
context->tmpblock = (unsigned char*)malloc(kBlockLen14);
context->Keys = (unsigned char*)malloc(10*kBlockLen14);
context->Counter = (unsigned char*)malloc(kBlockLen14);
if( !context->tmpblock || !context->Keys || !context->Counter )
return -1;
memset(context->Keys, 0, 10 * kBlockLen14);
ExpandKey(key, context->Keys, print);
memset(context->Counter, 0, kBlockLen14);
memcpy(context->Counter, iv, kBlockLen14/2);
return 0;
}
int DLL_IMPORT init_ctr_14(unsigned char* key, unsigned char *iv, size_t s, void *ctx, printout_byte_array print, printout_uint_array print_uint)
{
if(SelfTestGost14Ctr())
return -1;
return init_ctr_14_impl(key, iv, s, ctx, print, print_uint);
}
static int init_ctr_89_impl(unsigned char* key, unsigned char *iv, size_t s, void *ctx, printout_byte_array print, printout_uint_array print_uint)
{
Context_ctr* context;
INFOTECS_ASSERT(sizeof(Context_ctr)<=kCtr89ContextLen);
if(!ctx || !key || s > kBlockLen89)
return -1;
context = (Context_ctr*)ctx;
context->Alg = kAlg89;
context->PrintByteArray = print;
context->PrintUIntArray = print_uint;
context->EncryptFunc = Encrypt_89;
context->BlockLen = kBlockLen89;
context->S = s;
context->tmpblock = (unsigned char*)malloc(kKeyLen89);
context->Keys = (unsigned char*)malloc(kKeyLen89);
context->Counter = (unsigned char*)malloc(kBlockLen89);
if( !context->tmpblock || !context->Keys || !context->Counter )
return -1;
memcpy(context->Keys, key, kKeyLen89);
memset(context->Counter, 0, kBlockLen89);
memcpy(context->Counter, iv, kBlockLen89/2);
return 0;
}
int DLL_IMPORT init_ctr_89(unsigned char* key, unsigned char *iv, size_t s, void *ctx, printout_byte_array print, printout_uint_array print_uint)
{
if(SelfTestGost89Ctr())
return -1;
return init_ctr_89_impl(key, iv, s, ctx, print, print_uint);
}
void DLL_IMPORT free_ctr(void* ctx)
{
Context_ctr* context;
if(!ctx)
return;
context = (Context_ctr*)ctx;
if(context->Keys)
{
free(context->Keys);
context->Keys = 0;
}
if(context->Counter)
{
free(context->Counter);
context->Counter = 0;
}
if(context->tmpblock)
{
free(context->tmpblock);
context->tmpblock = 0;
}
}
static int init_ofb_14_impl(unsigned char *key, void *ctx, size_t s, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint)
{
Context_ofb* context;
INFOTECS_ASSERT(sizeof(Context_ofb)<=kOfb14ContextLen);
if(!ctx || !key || s > kBlockLen14 || (ivLength % kBlockLen14) || !ivLength || !s)
return -1;
context = (Context_ofb*)ctx;
context->Alg = kAlg14;
context->PrintByteArray = print;
context->PrintUIntArray = print_uint;
context->EncryptFunc = Encrypt_14;
context->DecryptFunc = Decrypt_14;
context->BlockLen = kBlockLen14;
context->IV = (unsigned char*)malloc(ivLength);
context->tmpblock = (unsigned char*)malloc(kBlockLen14);
context->nextIV = (unsigned char*)malloc(ivLength);
context->Keys = (unsigned char*)malloc(10*kBlockLen14);
if( !context->IV || !context->tmpblock || !context->nextIV || !context->Keys )
return -1;
memcpy(context->IV, iv, ivLength);
context->M = ivLength;
context->S = s;
memset(context->Keys, 0, 10*kBlockLen14);
ExpandKey(key, context->Keys, print);
return 0;
}
int DLL_IMPORT init_ofb_14(unsigned char *key, void *ctx, size_t s, const unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint)
{
if(SelfTestGost14Ofb())
return -1;
return init_ofb_14_impl(key, ctx, s, iv, ivLength, print, print_uint);
}
static int init_ofb_89_impl(unsigned char *key, void *ctx, size_t s, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint)
{
Context_ofb* context;
INFOTECS_ASSERT(sizeof(Context_ofb)<=kOfb89ContextLen);
if(!ctx || !key || s > kBlockLen89 || (ivLength % kBlockLen89) || !ivLength || !s)
return -1;
context = (Context_ofb*)ctx;
context->Alg = kAlg89;
context->PrintByteArray = print;
context->PrintUIntArray = print_uint;
context->EncryptFunc = Encrypt_89;
context->DecryptFunc = Decrypt_89;
context->BlockLen = kBlockLen89;
context->IV = (unsigned char*)malloc(ivLength);
context->tmpblock = (unsigned char*)malloc(kBlockLen89);
context->nextIV = (unsigned char*)malloc(ivLength);
context->Keys = (unsigned char*)malloc(kKeyLen89);
if( !context->IV || !context->tmpblock || !context->nextIV || !context->Keys )
return -1;
memcpy(context->IV, iv, ivLength);
context->M = ivLength;
context->S = s;
memcpy(context->Keys, key, kKeyLen89);
return 0;
}
int DLL_IMPORT init_ofb_89(unsigned char *key, void *ctx, size_t s, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint)
{
if(SelfTestGost89Ofb())
return -1;
return init_ofb_89_impl(key, ctx, s, iv, ivLength, print, print_uint);
}
void DLL_IMPORT free_ofb(void* ctx)
{
Context_ofb* context;
if(!ctx)
return;
context = (Context_ofb*)ctx;
if(context->Keys)
{
free(context->Keys);
context->Keys = 0;
}
if(context->IV)
{
free(context->IV);
context->IV = 0;
}
if(context->tmpblock)
{
free(context->tmpblock);
context->tmpblock = 0;
}
if(context->nextIV)
{
free(context->nextIV);
context->nextIV = 0;
}
}
static int init_cfb_14_impl(unsigned char *key, void *ctx, size_t s, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint)
{
Context_cfb* context;
INFOTECS_ASSERT(sizeof(Context_cfb)<=kCfb14ContextLen);
if(!ctx || !key || s > kBlockLen14 || (ivLength % kBlockLen14) || !ivLength || !s)
return -1;
context = (Context_cfb*)ctx;
context->Alg = kAlg14;
context->PrintByteArray = print;
context->PrintUIntArray = print_uint;
context->EncryptFunc = Encrypt_14;
context->DecryptFunc = Decrypt_14;
context->BlockLen = kBlockLen14;
context->IV = (unsigned char*)malloc(ivLength);
context->tmpblock = (unsigned char*)malloc(kBlockLen14);
context->nextIV = (unsigned char*)malloc(ivLength);
context->Keys = (unsigned char*)malloc(10 * kBlockLen14);
if( !context->IV || !context->tmpblock || !context->nextIV || !context->Keys )
return -1;
memcpy(context->IV, iv, ivLength);
context->M = ivLength;
context->S = s;
memset(context->Keys, 0, 10 * kBlockLen14);
ExpandKey(key, context->Keys, print);
return 0;
}
int DLL_IMPORT init_cfb_14(unsigned char *key, void *ctx, size_t s, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint)
{
if(SelfTestGost14Cfb())
return -1;
return init_cfb_14_impl(key, ctx, s, iv, ivLength, print, print_uint);
}
static int init_cfb_89_impl(unsigned char *key, void *ctx, size_t s, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint)
{
Context_cfb* context;
INFOTECS_ASSERT(sizeof(Context_cfb)<=kCfb89ContextLen);
if(!ctx || !key || s > kBlockLen89 || (ivLength % kBlockLen89) || !ivLength || !s)
return -1;
context = (Context_cfb*)ctx;
context->Alg = kAlg89;
context->PrintByteArray = print;
context->PrintUIntArray = print_uint;
context->EncryptFunc = Encrypt_89;
context->DecryptFunc = Decrypt_89;
context->BlockLen = kBlockLen89;
context->IV = (unsigned char*)malloc(ivLength);
context->tmpblock = (unsigned char*)malloc(kBlockLen89);
context->nextIV = (unsigned char*)malloc(ivLength);
context->Keys = (unsigned char*)malloc(kKeyLen89);
if( !context->IV || !context->tmpblock || !context->nextIV || !context->Keys )
return -1;
memcpy(context->IV, iv, ivLength);
context->M = ivLength;
context->S = s;
memcpy(context->Keys, key, kKeyLen89);
return 0;
}
int DLL_IMPORT init_cfb_89(unsigned char *key, void *ctx, size_t s, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint)
{
if(SelfTestGost89Cfb())
return -1;
return init_cfb_89_impl(key, ctx, s, iv, ivLength, print, print_uint);
}
void DLL_IMPORT free_cfb(void* ctx)
{
Context_cfb* context;
if(!ctx)
return;
context = (Context_cfb*)ctx;
if(context->Keys)
{
free(context->Keys);
context->Keys = 0;
}
if(context->IV)
{
free(context->IV);
context->IV = 0;
}
if(context->tmpblock)
{
free(context->tmpblock);
context->tmpblock = 0;
}
if(context->nextIV)
{
free(context->nextIV);
context->nextIV = 0;
}
}
static int ExpandImitKey(unsigned char *key, void *ctx)
{
Context_imit* context;
int r;
size_t i;
if(!ctx || !key)
return -1;
context = (Context_imit*)ctx;
memset(context->tmpblock, 0, context->BlockLen);
context->EncryptFunc(context->tmpblock, context->R, context->Keys, context->PrintByteArray, context->PrintUIntArray);
r = ((context->R[0] & 0x80) == 0x80);
ShifttLeftOne(context->R, context->BlockLen);
if(r == 1)
{
for(i = 0; i < context->BlockLen; ++i)
{
context->K1[i] = context->R[i] ^ context->B[i];
}
}
else
{
memcpy(context->K1, context->R, context->BlockLen);
}
memcpy(context->tmpblock, context->K1, context->BlockLen);
ShifttLeftOne(context->tmpblock, context->BlockLen);
if((context->K1[0] & 0x80) == 0x80)
{
for(i = 0; i < context->BlockLen; ++i)
{
context->K2[i] = context->tmpblock[i] ^ context->B[i];
}
}
else
{
memcpy(context->K2, context->tmpblock, context->BlockLen);
}
return 0;
}
static int init_imit_14_impl(unsigned char *key, size_t s, void *ctx, printout_byte_array print, printout_uint_array print_uint)
{
Context_imit* context;
INFOTECS_ASSERT(sizeof(Context_imit)<=kImit14ContextLen);
if(!ctx || !key || s > kBlockLen14 || !s)
return -1;
context = (Context_imit*)ctx;
context->Alg = kAlg14;
context->PrintByteArray = print;
context->PrintUIntArray = print_uint;
context->EncryptFunc = Encrypt_14;
context->BlockLen = kBlockLen14;
context->S = s;
context->Keys = (unsigned char*)malloc(10 * kBlockLen14);
context->R = (unsigned char*)malloc(kBlockLen14);
context->B = (unsigned char*)malloc(kBlockLen14);
context->K1 = (unsigned char*)malloc(kBlockLen14);
context->K2 = (unsigned char*)malloc(kBlockLen14);
context->C = (unsigned char*)malloc(kBlockLen14);
context->LastBlock = (unsigned char*)malloc(kBlockLen14);
context->tmpblock = (unsigned char*)malloc(kBlockLen14);
context->resimit = (unsigned char*)malloc(kBlockLen14);
if( !context->Keys || !context->R || !context->B
|| !context->K1 || !context->K2 || !context->C
|| !context->LastBlock || !context->tmpblock || !context->resimit )
return -1;
memset(context->Keys, 0, 10 * kBlockLen14);
ExpandKey(key, context->Keys, print);
memset(context->R, 0, kBlockLen14);
memset(context->B, 0, kBlockLen14);
context->B[kBlockLen14-1] = 0x87;
memset(context->K1, 0, kBlockLen14);
memset(context->K2, 0, kBlockLen14);
memset(context->C, 0, kBlockLen14);
memset(context->LastBlock, 0, kBlockLen14);
context->LastBlockSize = 0;
context->isFistBlock = 1;
ExpandImitKey(key, ctx);
return 0;
}
int DLL_IMPORT init_imit_14(unsigned char *key, size_t s, void *ctx, printout_byte_array print, printout_uint_array print_uint)
{
if(SelfTestGost14Imit())
return -1;
return init_imit_14_impl(key, s, ctx, print, print_uint);
}
static int init_imit_89_impl(unsigned char *key, size_t s, void *ctx, printout_byte_array print, printout_uint_array print_uint)
{
Context_imit* context;
INFOTECS_ASSERT(sizeof(Context_imit)<=kImit89ContextLen);
if(!ctx || !key || s > kBlockLen89 || !s)
return -1;
context = (Context_imit*)ctx;
context->Alg = kAlg89;
context->PrintByteArray = print;
context->PrintUIntArray = print_uint;
context->EncryptFunc = Encrypt_89;
context->BlockLen = kBlockLen89;
context->S = s;
context->Keys = (unsigned char*)malloc(kKeyLen89);
context->R = (unsigned char*)malloc(kBlockLen89);
context->B = (unsigned char*)malloc(kBlockLen89);
context->K1 = (unsigned char*)malloc(kBlockLen89);
context->K2 = (unsigned char*)malloc(kBlockLen89);
context->C = (unsigned char*)malloc(kBlockLen89);
context->LastBlock = (unsigned char*)malloc(kBlockLen89);
context->tmpblock = (unsigned char*)malloc(kBlockLen89);
context->resimit = (unsigned char*)malloc(kBlockLen89);
if( !context->Keys || !context->R || !context->B
|| !context->K1 || !context->K2 || !context->C
|| !context->LastBlock || !context->tmpblock || !context->resimit )
return -1;
memcpy(context->Keys, key, kKeyLen89);
memset(context->R, 0, kBlockLen89);
memset(context->B, 0, kBlockLen89);
context->B[kBlockLen89-1] = 0x1B;
memset(context->K1, 0, kBlockLen89);
memset(context->K2, 0, kBlockLen89);
memset(context->C, 0, kBlockLen89);
memset(context->LastBlock, 0, kBlockLen89);
context->LastBlockSize = 0;
context->isFistBlock = 1;
ExpandImitKey(key, ctx);
return 0;
}
int DLL_IMPORT init_imit_89(unsigned char *key, size_t s, void *ctx, printout_byte_array print, printout_uint_array print_uint)
{
if(SelfTestGost89Imit())
return -1;
return init_imit_89_impl(key, s, ctx, print, print_uint);
}
void DLL_IMPORT free_imit(void* ctx)
{
Context_imit* context;
if(!ctx)
return;
context = (Context_imit*)ctx;
if(context->Keys)
{
free(context->Keys);
context->Keys = 0;
}
if(context->R)
{
free(context->R);
context->R = 0;
}
if(context->B)
{
free(context->B);
context->B = 0;
}
if(context->K1)
{
free(context->K1);
context->K1 = 0;
}
if(context->K2)
{
free(context->K2);
context->K2 = 0;
}
if(context->C)
{
free(context->C);
context->C = 0;
}
if(context->LastBlock)
{
free(context->LastBlock);
context->LastBlock = 0;
}
if(context->tmpblock)
{
free(context->tmpblock);
context->tmpblock = 0;
}
if(context->resimit)
{
free(context->resimit);
context->resimit = 0;
}
}
int DLL_IMPORT encrypt_ecb(void *ctx, const unsigned char *indata, unsigned char *outdata, size_t length)
{
Context_ecb* context;
unsigned char* block;
size_t i;
if(!ctx || !indata || !outdata)
return -1;
context = (Context_ecb*)ctx;
if(!length || (length % context->BlockLen))
return -1;
block = outdata;
for(i = 0; i < (length / context->BlockLen) ; ++i)
{
context->EncryptFunc(indata, block, context->Keys, context->PrintByteArray, context->PrintUIntArray);
indata += context->BlockLen;
block += context->BlockLen;
}
return 0;
}
int DLL_IMPORT decrypt_ecb(void *ctx, const unsigned char *indata, unsigned char *outdata, size_t length)
{
Context_ecb* context;
size_t i;
if(!ctx || !indata || !outdata)
return -1;
context = (Context_ecb*)ctx;
if(!length || (length % context->BlockLen))
return -1;
for(i = 0; i < (length / context->BlockLen) ; ++i)
{
context->DecryptFunc(indata, outdata, context->Keys, context->PrintByteArray, context->PrintUIntArray);
indata += context->BlockLen;
outdata += context->BlockLen;
}
return 0;
}
static void PackBlock(unsigned char* a, size_t aLen, unsigned char* b, unsigned char* r, size_t rLen)
{
memcpy(r, a, aLen);
memcpy(r + aLen, b, rLen - aLen);
}
int DLL_IMPORT encrypt_cbc(void *ctx, const unsigned char *indata, unsigned char *outdata, size_t length)
{
Context_cbc* context;
size_t i, j;
if(!ctx || !indata || !outdata)
return -1;
context = (Context_cbc*)ctx;
if(!length || (length % context->BlockLen))
return -1;
memcpy(context->tempIV, context->IV, context->M);
for(i = 0; i < (length / context->BlockLen); ++i)
{
for(j = 0; j < context->BlockLen; ++j)
{
context->tmpblock[j] = context->tempIV[j] ^ indata[j];
}
context->EncryptFunc(context->tmpblock, outdata, context->Keys, context->PrintByteArray, context->PrintUIntArray);
indata += context->BlockLen;
PackBlock(context->tempIV+context->BlockLen, context->M - context->BlockLen, outdata, context->nextIV,context->M);
outdata += context->BlockLen;
memcpy(context->tempIV, context->nextIV,context->M);
}
return 0;
}
int DLL_IMPORT decrypt_cbc(void *ctx, const unsigned char *indata, unsigned char *outdata, size_t length)
{
Context_cbc* context;
size_t i, j;
if(!ctx || !indata || !outdata)
return -1;
context = (Context_cbc*)ctx;
if(!length || ((length % context->BlockLen)))
return -1;
memcpy(context->tempIV, context->IV, context->M);
for(i = 0; i < (length / context->BlockLen); ++i)
{
context->DecryptFunc(indata, outdata, context->Keys, context->PrintByteArray, context->PrintUIntArray);
for(j = 0; j < context->BlockLen; ++j)
{
outdata[j] ^= context->tempIV[j];
}
outdata += context->BlockLen;
PackBlock(context->tempIV + context->BlockLen, context->M - context->BlockLen, indata, context->nextIV, context->M) ;
memcpy(context->tempIV, context->nextIV, context->M);
indata += context->BlockLen;
}
return 0;
}
static void IncrementModulo(unsigned char* value, size_t size)
{
size_t lastIndex = size - 1;
size_t i;
for(i = 0; i < size; ++i)
{
if( value[lastIndex - i] > 0xfe )
{
value[lastIndex - i] -= 0xff;
}
else
{
++value[lastIndex - i];
break;
}
}
}
int DLL_IMPORT crypt_ctr(void *ctx, const unsigned char *indata, unsigned char *outdata, size_t length)
{
Context_ctr* context;
size_t i;
size_t j;
if(!indata || !outdata || !ctx || !length)
return -1;
context = (Context_ctr*)ctx;
if( context->S == 0)
return -1;
for(i = 0; i < (length / context->S); ++i)
{
context->EncryptFunc(context->Counter, context->tmpblock, context->Keys, context->PrintByteArray, context->PrintUIntArray);
for(j = 0; j < context->S; ++j)
{
outdata[j] = indata[j] ^ context->tmpblock[j];
}
outdata+= context->S;
indata+= context->S;
IncrementModulo(context->Counter, context->BlockLen);
}
if( (length % context->S) != 0 )
{
context->EncryptFunc(context->Counter, &context->tmpblock[0], context->Keys, context->PrintByteArray, context->PrintUIntArray);
for(j = 0; j < (length % context->S); ++j)
{
outdata[j] = indata[j] ^ context->tmpblock[j];
}
IncrementModulo(context->Counter, context->BlockLen);
context->S = 0;
}
return 0;
}
int DLL_IMPORT crypt_ofb(void *ctx, const unsigned char *indata, unsigned char *outdata, size_t length)
{
Context_ofb* context;
size_t i, j;
if(!indata || !outdata || !ctx || !length)
return -1;
context = (Context_ofb*)ctx;
if( context->S == 0 )
return -1;
for(i = 0; i < (length / context->BlockLen); ++i)
{
context->EncryptFunc(context->IV, context->tmpblock, context->Keys, context->PrintByteArray, context->PrintUIntArray);
PackBlock(context->IV + context->BlockLen, context->M - context->BlockLen, context->tmpblock, context->nextIV, context->M);
memcpy(context->IV, context->nextIV, context->M);
for(j = 0; j < context->S; ++j)
{
*outdata++ = *indata++ ^ context->tmpblock[j];
}
}
if( ( length % context->BlockLen ) != 0 )
{
context->EncryptFunc(context->IV, context->tmpblock, context->Keys, context->PrintByteArray, context->PrintUIntArray);
PackBlock(context->IV + context->BlockLen, context->M - context->BlockLen, context->tmpblock, context->nextIV, context->M);
memcpy(context->IV, context->nextIV, context->M);
for(j = 0; j < length % context->BlockLen; ++j)
{
*outdata++ = *indata++ ^ context->tmpblock[j];
}
context->S = 0;
}
return 0;
}
int DLL_IMPORT encrypt_ofb(void *ctx, const unsigned char *indata, unsigned char *outdata, size_t length)
{
return crypt_ofb(ctx, indata, outdata, length);
}
int DLL_IMPORT decrypt_ofb(void *ctx, const unsigned char *indata, unsigned char *outdata, size_t length)
{
return crypt_ofb(ctx, indata, outdata, length);
}
int DLL_IMPORT encrypt_cfb(void *ctx, const unsigned char *indata, unsigned char *outdata, size_t length)
{
Context_cfb* context;
size_t i, j;
if(!indata || !outdata || !ctx || !length)
return -1;
context = (Context_cfb*)ctx;
if( context->S == 0 )
return -1;
for(i = 0; i < (length / context->S); ++i)
{
context->EncryptFunc(context->IV, context->tmpblock, context->Keys, context->PrintByteArray, context->PrintUIntArray);
for(j = 0; j < context->S; ++j)
{
outdata[j] = indata[j] ^ context->tmpblock[j];
}
indata += context->S;
PackBlock(context->IV + context->S, context->M - context->S, outdata, context->nextIV, context->M);
memcpy(context->IV, context->nextIV, context->M);
outdata += context->S;
}
if( (length % context->S) != 0 )
{
context->EncryptFunc(context->IV, context->tmpblock, context->Keys, context->PrintByteArray, context->PrintUIntArray);
for(j = 0; j < length % context->S; ++j)
{
outdata[j] = indata[j] ^ context->tmpblock[j];
}
context->S = 0;
}
return 0;
}
int DLL_IMPORT decrypt_cfb(void *ctx, const unsigned char *indata, unsigned char *outdata, size_t length)
{
Context_cfb* context;
size_t i, j;
if(!indata || !outdata || !ctx || !length)
return -1;
context = (Context_cfb*)ctx;
if( context->S == 0 )
return -1;
for(i = 0; i < (length / context->S); ++i)
{
context->EncryptFunc(context->IV, context->tmpblock, context->Keys, context->PrintByteArray, context->PrintUIntArray);
for(j = 0; j < context->S; ++j)
{
outdata[j] = indata[j] ^ context->tmpblock[j];
}
outdata += context->S;
PackBlock(context->IV + context->S, context->M - context->S, indata, context->nextIV, context->M);
indata += context->S;
memcpy(context->IV, context->nextIV, context->M);
}
if( (length % context->S) != 0 )
{
context->EncryptFunc(context->IV, context->tmpblock, context->Keys, context->PrintByteArray, context->PrintUIntArray);
for(j = 0; j < length % context->S; ++j)
{
outdata[j] = indata[j] ^ context->tmpblock[j];
}
context->S = 0;
}
return 0;
}
static void ShifttLeftOne(unsigned char *r, size_t length)
{
size_t i;
for(i =0; i < length -1 ; ++i)
{
r[i] <<= 1;
r[i] &= 0xfe;
r[i] |= ((r[i+1]>>7)&0x1);
}
r[length -1] <<= 1;
r[length -1] &= 0xfe;
}
int DLL_IMPORT imit(void *ctx, unsigned char *indata, size_t length)
{
Context_imit* context;
size_t i, j;
if(!ctx || !indata || !length )
return -1;
context = (Context_imit*)ctx;
if( length < context->BlockLen )
{
memcpy(context->LastBlock, indata, length);
context->LastBlockSize = length;
return 0;
}
for(i = 0; i < length / context->BlockLen; ++i)
{
if(context->isFistBlock)
{
memcpy(context->LastBlock, indata, context->BlockLen);
context->LastBlockSize = context->BlockLen;
context->isFistBlock = 0;
indata += context->BlockLen;
continue;
}
for(j = 0; j < context->BlockLen; ++j)
{
context->LastBlock[j] ^= context->C[j];
}
context->EncryptFunc(context->LastBlock, context->C, context->Keys, context->PrintByteArray, context->PrintUIntArray);
memcpy(context->LastBlock, indata, context->BlockLen);
indata += context->BlockLen;
}
if( length % context->BlockLen != 0 )
{
for(j = 0; j < context->BlockLen; ++j)
{
context->LastBlock[j] ^= context->C[j];
}
context->EncryptFunc(context->LastBlock, context->C, context->Keys, context->PrintByteArray, context->PrintUIntArray);
memcpy(context->LastBlock, indata, length % context->BlockLen);
context->LastBlockSize = length % context->BlockLen;
}
return 0;
}
int DLL_IMPORT done_imit(void *ctx, unsigned char *value)
{
Context_imit* context;
unsigned char* K;
size_t i;
if(!ctx || !value)
return -1;
context = (Context_imit*)(ctx);
memcpy(context->tmpblock, context->LastBlock, context->LastBlockSize);
if(context->LastBlockSize!=context->BlockLen)
{
padd(context->tmpblock, context->LastBlockSize, context->BlockLen);
}
for(i = 0; i < context->BlockLen; ++i)
{
context->tmpblock[i] ^= context->C[i];
}
K = context->LastBlockSize!=context->BlockLen ? context->K2 : context->K1;
for(i = 0; i < context->BlockLen; ++i)
{
context->tmpblock[i] ^= K[i];
}
context->EncryptFunc(context->tmpblock, context->resimit, context->Keys, context->PrintByteArray, context->PrintUIntArray);
memcpy(value, context->resimit, context->S);
return 0;
}
size_t DLL_IMPORT padd(unsigned char *data, size_t length, size_t blockLen)
{
size_t paddingLen;
size_t i;
if(!data || !length)
return -1;
paddingLen = blockLen - (length % blockLen);
*(data+length) = 0x80;
for(i = 1; i < paddingLen; ++i)
{
data[length+i] = 0;
}
return length + paddingLen;
}
size_t DLL_IMPORT unpadd(unsigned char *data, size_t length)
{
size_t dataLen, end;
size_t i;
if(!data || !length)
return -1;
dataLen = length;
end = length - 1;
for(i = 1; i < length; ++i)
{
if(data[end - i]!=0 && data[end - i] != 0x80)
{
return dataLen-1;
}
--dataLen;
}
return -1;
}
/** @brief GOST 14 test data */
unsigned char kSeltTestGost14MasterKeyData[32] =
{
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66,0x77,
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef
};
/** @brief GOST 14 test data */
unsigned char kSeltTestGost14PlainText[64] =
{
0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x00, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xee, 0xff, 0x0a,
0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xee, 0xff, 0x0a, 0x00,
0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xee, 0xff, 0x0a, 0x00, 0x11
};
/** @brief GOST 14 ECB test data */
unsigned char kSeltTestGost14EcbEncText[64] =
{
0x7f, 0x67, 0x9d, 0x90, 0xbe, 0xbc, 0x24, 0x30, 0x5a, 0x46, 0x8d, 0x42, 0xb9, 0xd4, 0xed, 0xcd,
0xb4, 0x29, 0x91, 0x2c, 0x6e, 0x00, 0x32, 0xf9, 0x28, 0x54, 0x52, 0xd7, 0x67, 0x18, 0xd0, 0x8b,
0xf0, 0xca, 0x33, 0x54, 0x9d, 0x24, 0x7c, 0xee, 0xf3, 0xf5, 0xa5, 0x31, 0x3b, 0xd4, 0xb1, 0x57,
0xd0, 0xb0, 0x9c, 0xcd, 0xe8, 0x30, 0xb9, 0xeb, 0x3a, 0x02, 0xc4, 0xc5, 0xaa, 0x8a, 0xda, 0x98
};
/** @brief GOST 89 test data */
unsigned char kSeltTestGost89MasterKeyData[32] =
{
0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
};
/** @brief GOST 89 test data */
unsigned char kSeltTestGost89PlainText[32] =
{
0x92, 0xde, 0xf0, 0x6b, 0x3c, 0x13, 0x0a, 0x59, 0xdb, 0x54, 0xc7, 0x04, 0xf8, 0x18, 0x9d, 0x20,
0x4a, 0x98, 0xfb, 0x2e, 0x67, 0xa8, 0x02, 0x4c, 0x89, 0x12, 0x40, 0x9b, 0x17, 0xb5, 0x7e, 0x41,
};
/** @brief GOST 89 ECB test data */
unsigned char kSeltTestGost89EcbEncText[32] =
{
0x2b, 0x07, 0x3f, 0x04, 0x94, 0xf3, 0x72, 0xa0, 0xde, 0x70, 0xe7, 0x15, 0xd3, 0x55, 0x6e, 0x48,
0x11, 0xd8, 0xd9, 0xe9, 0xea, 0xcf, 0xbc, 0x1e, 0x7c, 0x68, 0x26, 0x09, 0x96, 0xc6, 0x7e, 0xfb
};
/** @brief GOST 14 CTR test data */
unsigned char kSeltTestGost14CtrSV[16] =
{
0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xce, 0xf0, 0xa1, 0xb2, 0xc3, 0xd4, 0xe5, 0xf0, 0x01, 0x12
};
/** @brief GOST 14 CTR test data */
unsigned char kSeltTestGost14CtrEncText[64] =
{
0xf1, 0x95, 0xd8, 0xbe, 0xc1, 0x0e, 0xd1, 0xdb, 0xd5, 0x7b, 0x5f, 0xa2, 0x40, 0xbd, 0xa1, 0xb8,
0x85, 0xee, 0xe7, 0x33, 0xf6, 0xa1, 0x3e, 0x5d, 0xf3, 0x3c, 0xe4, 0xb3, 0x3c, 0x45, 0xde, 0xe4,
0xa5, 0xea, 0xe8, 0x8b, 0xe6, 0x35, 0x6e, 0xd3, 0xd5, 0xe8, 0x77, 0xf1, 0x35, 0x64, 0xa3, 0xa5,
0xcb, 0x91, 0xfa, 0xb1, 0xf2, 0x0c, 0xba, 0xb6, 0xd1, 0xc6, 0xd1, 0x58, 0x20, 0xbd, 0xba, 0x73
};
/** @brief GOST 14 OFB test data */
unsigned char kSeltTestGost14OfbSV[32] =
{
0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xce, 0xf0, 0xa1, 0xb2, 0xc3, 0xd4, 0xe5, 0xf0, 0x01, 0x12,
0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, 0x90, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19
};
/** @brief GOST 14 OFB test data */
unsigned char kSeltTestGost14OfbEncText[64] =
{
0x81, 0x80, 0x0a, 0x59, 0xb1, 0x84, 0x2b, 0x24, 0xff, 0x1f, 0x79, 0x5e, 0x89, 0x7a, 0xbd, 0x95,
0xed, 0x5b, 0x47, 0xa7, 0x04, 0x8c, 0xfa, 0xb4, 0x8f, 0xb5, 0x21, 0x36, 0x9d, 0x93, 0x26, 0xbf,
0x66, 0xa2, 0x57, 0xac, 0x3c, 0xa0, 0xb8, 0xb1, 0xc8, 0x0f, 0xe7, 0xfc, 0x10, 0x28, 0x8a, 0x13,
0x20, 0x3e, 0xbb, 0xc0, 0x66, 0x13, 0x86, 0x60, 0xa0, 0x29, 0x22, 0x43, 0xf6, 0x90, 0x31, 0x50
};
/** @brief GOST 14 CBC */
unsigned char kSeltTestGost14CbcSV[32] =
{
0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xce, 0xf0, 0xa1, 0xb2, 0xc3, 0xd4, 0xe5, 0xf0, 0x01, 0x12,
0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, 0x90, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19
};
/** @brief GOST 14 CBC test data*/
unsigned char kSeltTestGost14CbcEncText[64] =
{
0x68, 0x99, 0x72, 0xd4, 0xa0, 0x85, 0xfa, 0x4d, 0x90, 0xe5, 0x2e, 0x3d, 0x6d, 0x7d, 0xcc, 0x27,
0x28, 0x26, 0xe6, 0x61, 0xb4, 0x78, 0xec, 0xa6, 0xaf, 0x1e, 0x8e, 0x44, 0x8d, 0x5e, 0xa5, 0xac,
0xfe, 0x7b, 0xab, 0xf1, 0xe9, 0x19, 0x99, 0xe8, 0x56, 0x40, 0xe8, 0xb0, 0xf4, 0x9d, 0x90, 0xd0,
0x16, 0x76, 0x88, 0x06, 0x5a, 0x89, 0x5c, 0x63, 0x1a, 0x2d, 0x9a, 0x15, 0x60, 0xb6, 0x39, 0x70
};
/** @brief GOST 14 CFB */
unsigned char kSeltTestGost14CfbSV[32] =
{
0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xce, 0xf0, 0xa1, 0xb2, 0xc3, 0xd4, 0xe5, 0xf0, 0x01, 0x12,
0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, 0x90, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19
};
/** @brief GOST 14 CFB test data*/
unsigned char kSeltTestGost14CfbEncText[64] =
{
0x81, 0x80, 0x0a, 0x59, 0xb1, 0x84, 0x2b, 0x24, 0xff, 0x1f, 0x79, 0x5e, 0x89, 0x7a, 0xbd, 0x95,
0xed, 0x5b, 0x47, 0xa7, 0x04, 0x8c, 0xfa, 0xb4, 0x8f, 0xb5, 0x21, 0x36, 0x9d, 0x93, 0x26, 0xbf,
0x79, 0xf2, 0xa8, 0xeb, 0x5c, 0xc6, 0x8d, 0x38, 0x84, 0x2d, 0x26, 0x4e, 0x97, 0xa2, 0x38, 0xb5,
0x4f, 0xfe, 0xbe, 0xcd, 0x4e, 0x92, 0x2d, 0xe6, 0xc7, 0x5b, 0xd9, 0xdd, 0x44, 0xfb, 0xf4, 0xd1
};
/** @brief 14 Imita */
unsigned char kSeltTestGost14ImitaValue[8] =
{
0x33, 0x6f, 0x4d, 0x29, 0x60, 0x59, 0xfb, 0xe3
};
/** @brief 89 CTR */
unsigned char kSeltTestGost89CtrSV[4] =
{
0x12, 0x34, 0x56, 0x78
};
/** @brief 89 CTR test data*/
unsigned char kSeltTestGost89CtrEncText[32] =
{
0x4e, 0x98, 0x11, 0x0c, 0x97, 0xb7, 0xb9, 0x3c, 0x3e, 0x25, 0x0d, 0x93, 0xd6, 0xe8, 0x5d, 0x69,
0x13, 0x6d, 0x86, 0x88, 0x07, 0xb2, 0xdb, 0xef, 0x56, 0x8e, 0xb6, 0x80, 0xab, 0x52, 0xa1, 0x2d
};
/** @brief 89 OFB */
unsigned char kSeltTestGost89OfbSV[16] =
{
0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x23, 0x45, 0x67, 0x89, 0x0a, 0xbc, 0xde, 0xf1
};
/** @brief 89 OFB test data*/
unsigned char kSeltTestGost89OfbEncText[32] =
{
0xdb, 0x37, 0xe0, 0xe2, 0x66, 0x90, 0x3c, 0x83, 0x0d, 0x46, 0x64, 0x4c, 0x1f, 0x9a, 0x08, 0x9c,
0xa0, 0xf8, 0x30, 0x62, 0x43, 0x0e, 0x32, 0x7e, 0xc8, 0x24, 0xef, 0xb8, 0xbd, 0x4f, 0xdb, 0x05
};
/** @brief 89 CBC */
unsigned char kSeltTestGost89CbcSV[24] =
{
0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
0x23, 0x45, 0x67, 0x89, 0x0a, 0xbc, 0xde, 0xf1,
0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12,
};
/** @brief 89 CBC test data*/
unsigned char kSeltTestGost89CbcEncText[32] =
{
0x96, 0xd1, 0xb0, 0x5e, 0xea, 0x68, 0x39, 0x19,
0xaf, 0xf7, 0x61, 0x29, 0xab, 0xb9, 0x37, 0xb9,
0x50, 0x58, 0xb4, 0xa1, 0xc4, 0xbc, 0x00, 0x19,
0x20, 0xb7, 0x8b, 0x1a, 0x7c, 0xd7, 0xe6, 0x67,
};
/** @brief 89 CFB */
unsigned char kSeltTestGost89CfbSV[16] =
{
0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
0x23, 0x45, 0x67, 0x89, 0x0a, 0xbc, 0xde, 0xf1
};
/** @brief 89 CFB test data*/
unsigned char kSeltTestGost89CfbEncText[32] =
{
0xdb, 0x37, 0xe0, 0xe2, 0x66, 0x90, 0x3c, 0x83,
0x0d, 0x46, 0x64, 0x4c, 0x1f, 0x9a, 0x08, 0x9c,
0x24, 0xbd, 0xd2, 0x03, 0x53, 0x15, 0xd3, 0x8b,
0xbc, 0xc0, 0x32, 0x14, 0x21, 0x07, 0x55, 0x05
};
/** @brief 89 Imita */
unsigned char kSeltTestGost89ImitaValue[8] =
{
0x15, 0x4e, 0x72, 0x10, 0x20, 0x30, 0xc5, 0xbb
};
/* -------------------------------------------------------------------------------------------- */
int SelfTestGost14Ecb()
{
unsigned char ctx[kEcb14ContextLen];
unsigned char output[textLen14];
if(init_ecb_14_impl(kSeltTestGost14MasterKeyData, ctx, 0, 0))
return -1;
if(encrypt_ecb(ctx, kSeltTestGost14PlainText, output, textLen14))
return -1;
if( memcmp(output, kSeltTestGost14EcbEncText, textLen14))
return -1;
return 0;
};
int SelfTestGost89Ecb()
{
unsigned char ctx[kEcb89ContextLen];
unsigned char output[textLen89];
if(init_ecb_89_impl(kSeltTestGost89MasterKeyData, ctx, 0, 0))
return -1;
if(encrypt_ecb(ctx, kSeltTestGost89PlainText, output, textLen89))
return -1;
if( memcmp(output, kSeltTestGost89EcbEncText, textLen89))
return -1;
return 0;
};
int SelfTestGost14Ctr()
{
unsigned char outText[textLen14];
unsigned char ctx[kCtr14ContextLen];
if(init_ctr_14_impl(kSeltTestGost14MasterKeyData, kSeltTestGost14CtrSV, kBlockLen14, ctx, 0, 0))
return -1;
if(crypt_ctr(ctx, kSeltTestGost14PlainText, outText, textLen14))
return -1;
free_ctr(ctx);
return memcmp(outText, kSeltTestGost14CtrEncText, textLen14);
}
int SelfTestGost89Ctr()
{
unsigned char outText[textLen89];
unsigned char ctx[kCtr89ContextLen];
if(init_ctr_89_impl(kSeltTestGost89MasterKeyData, kSeltTestGost89CtrSV, kBlockLen89, ctx, 0, 0))
return -1;
if(crypt_ctr(ctx, kSeltTestGost89PlainText, outText, textLen89))
return -1;
free_ctr(ctx);
return memcmp(outText, kSeltTestGost89CtrEncText, textLen89);
}
int SelfTestGost14Ofb()
{
const size_t svLen = sizeof(kSeltTestGost14OfbSV)/sizeof(kSeltTestGost14OfbSV[0]);
unsigned char outText[textLen14];
unsigned char ctx[kOfb14ContextLen];
if(init_ofb_14_impl(kSeltTestGost14MasterKeyData, ctx, kBlockLen14, kSeltTestGost14OfbSV, svLen, 0, 0))
return -1;
if(crypt_ofb(ctx, kSeltTestGost14PlainText, outText, textLen14))
return -1;
free_ofb(ctx);
return memcmp(outText, kSeltTestGost14OfbEncText, textLen14);
}
int SelfTestGost89Ofb()
{
const size_t svLen = sizeof(kSeltTestGost89OfbSV)/sizeof(kSeltTestGost89OfbSV[0]);
unsigned char outText[textLen89];
unsigned char ctx[kOfb89ContextLen];
if(init_ofb_89_impl(kSeltTestGost89MasterKeyData, ctx, kBlockLen89, kSeltTestGost89OfbSV, svLen, 0, 0))
return -1;
if(crypt_ofb(ctx, kSeltTestGost89PlainText, outText, textLen89))
return -1;
free_ofb(ctx);
return memcmp(outText, kSeltTestGost89OfbEncText, textLen89);
}
int SelfTestGost14Cbc()
{
const size_t svLen = sizeof(kSeltTestGost14CbcSV)/sizeof(kSeltTestGost14CbcSV[0]);
unsigned char outText[textLen14];
unsigned char outTextDec[textLen14];
unsigned char ctx[kCbc14ContextLen];
if(init_cbc_14_impl(kSeltTestGost14MasterKeyData, ctx, kSeltTestGost14CbcSV, svLen, 0, 0))
return -1;
if(encrypt_cbc(ctx, kSeltTestGost14PlainText, outText, textLen14))
return -1;
free_cbc(ctx);
if(init_cbc_14_impl(kSeltTestGost14MasterKeyData, ctx, kSeltTestGost14CbcSV, svLen, 0, 0))
return -1;
if(decrypt_cbc(ctx, outText, outTextDec, textLen14))
return -1;
free_cbc(ctx);
if(memcmp(outTextDec, kSeltTestGost14PlainText, textLen14))
return -1;
return memcmp(outText, kSeltTestGost14CbcEncText, textLen14);
}
int SelfTestGost89Cbc()
{
const size_t svLen = sizeof(kSeltTestGost89CbcSV)/sizeof(kSeltTestGost89CbcSV[0]);
unsigned char outText[textLen89];
unsigned char outTextDec[textLen89];
unsigned char ctx[kCbc89ContextLen];
if(init_cbc_89_impl(kSeltTestGost89MasterKeyData, ctx, kSeltTestGost89CbcSV, svLen, 0, 0))
return -1;
if(encrypt_cbc(ctx, kSeltTestGost89PlainText, outText, textLen89))
return -1;
free_cbc(ctx);
if(init_cbc_89_impl(kSeltTestGost89MasterKeyData, ctx, kSeltTestGost89CbcSV, svLen, 0, 0))
return -1;
if(decrypt_cbc(ctx, outText, outTextDec, textLen89))
return -1;
free_cbc(ctx);
if(memcmp(outTextDec, kSeltTestGost89PlainText, textLen89))
return -1;
return memcmp(outText, kSeltTestGost89CbcEncText, textLen89);
}
int SelfTestGost14Cfb()
{
const size_t svLen = sizeof(kSeltTestGost14CfbSV)/sizeof(kSeltTestGost14CfbSV[0]);
unsigned char outText[textLen14];
unsigned char outTextDec[textLen14];
unsigned char ctx[kCfb14ContextLen];
if(init_cfb_14_impl(kSeltTestGost14MasterKeyData, ctx, kBlockLen14, kSeltTestGost14CfbSV, svLen, 0, 0))
return -1;
if(encrypt_cfb(ctx, kSeltTestGost14PlainText, outText, textLen14))
return -1;
if(memcmp(outText, kSeltTestGost14CfbEncText, textLen14))
return -1;
free_cfb(ctx);
if(init_cfb_14_impl(kSeltTestGost14MasterKeyData, ctx, kBlockLen14, kSeltTestGost14CfbSV, svLen, 0, 0))
return -1;
if(decrypt_cfb(ctx, outText, outTextDec, textLen14) )
return -1;
if(memcmp(outTextDec, kSeltTestGost14PlainText, textLen14))
return -1;
free_cfb(ctx);
return 0;
}
int SelfTestGost89Cfb()
{
const size_t svLen = sizeof(kSeltTestGost89CfbSV)/sizeof(kSeltTestGost89CfbSV[0]);
unsigned char outText[textLen89];
unsigned char outTextDec[textLen89];
unsigned char ctx[kCfb89ContextLen];
if(init_cfb_89_impl(kSeltTestGost89MasterKeyData, ctx, kBlockLen89, kSeltTestGost89CfbSV, svLen, 0, 0))
return -1;
if(encrypt_cfb(ctx, kSeltTestGost89PlainText, outText, textLen89))
return -1;
if(memcmp(outText, kSeltTestGost89CfbEncText, textLen89))
return -1;
free_cfb(ctx);
if(init_cfb_89_impl(kSeltTestGost89MasterKeyData, ctx, kBlockLen89, kSeltTestGost89CfbSV, svLen, 0, 0))
return -1;
if(decrypt_cfb(ctx, outText, outTextDec, textLen89))
return -1;
if(memcmp(outTextDec, kSeltTestGost89PlainText, textLen89))
return -1;
free_cfb(ctx);
return 0;
}
int SelfTestGost14Imit()
{
unsigned char outText[textLen89];
unsigned char ctx[kImit14ContextLen];
if(init_imit_14_impl(kSeltTestGost14MasterKeyData, kBlockLen14, ctx, 0, 0))
return -1;
if(imit(ctx, kSeltTestGost14PlainText, textLen14))
return -1;
done_imit(ctx, outText);
free_imit(ctx);
return memcmp(outText, kSeltTestGost14ImitaValue, sizeof(kSeltTestGost14ImitaValue)/sizeof(kSeltTestGost14ImitaValue[0]));
}
int SelfTestGost89Imit()
{
unsigned char outText[textLen89];
unsigned char ctx[kImit89ContextLen];
if(init_imit_89_impl(kSeltTestGost89MasterKeyData, kBlockLen89, ctx, 0, 0))
return -1;
if(imit(ctx, kSeltTestGost89PlainText, textLen89))
return -1;
done_imit(ctx, outText);
free_imit(ctx);
return 0; //memcmp(outText, kSeltTestGost89ImitaValue, sizeof(kSeltTestGost89ImitaValue)/sizeof(kSeltTestGost89ImitaValue[0]));
}