1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

Merge mysql.com:/home/jimw/my/mysql-5.0-clean

into  mysql.com:/home/jimw/my/mysql-5.1-clean
This commit is contained in:
jimw@mysql.com
2006-04-30 13:27:38 -07:00
152 changed files with 11423 additions and 1564 deletions

View File

@ -291,6 +291,7 @@ client/my_decimal.h
client/my_user.c
client/mysql
client/mysql.cpp
client/mysql_upgrade
client/mysqladmin
client/mysqladmin.c
client/mysqladmin.cpp
@ -367,6 +368,9 @@ extra/resolve_stack_dump
extra/resolveip
extra/sql_state.h
extra/tztime.cc
extra/yassl/taocrypt/benchmark/benchmark
extra/yassl/taocrypt/test/test
extra/yassl/testsuite/testsuite
fcns.c
fcns.h
gdbinit
@ -679,6 +683,7 @@ mysql-test/mysql-test-run.log
mysql-test/mysql_test_run_new
mysql-test/ndb/ndbcluster
mysql-test/r/*.err
mysql-test/r/*.log
mysql-test/r/*.out
mysql-test/r/*.reject
mysql-test/r/alter_table.err
@ -1747,6 +1752,10 @@ tools/mysqlmanager
tools/mysqlmngd
tools/mysqltestmanager
tools/mysys_priv.h
unittest/examples/*.t
unittest/mysys/*.t
unittest/mytap/t/*.t
unittest/unit
vi.h
vio/*.ds?
vio/*.vcproj
@ -1758,9 +1767,3 @@ vio/viotest-sslconnect.cpp
vio/viotest.cpp
zlib/*.ds?
zlib/*.vcproj
mysql-test/r/*.log
client/mysql_upgrade
unittest/examples/*.t
unittest/mysys/*.t
unittest/mytap/t/*.t
unittest/unit

View File

@ -4,7 +4,7 @@
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=mysql_upgrade - Win32 Release
CFG=mysql_upgrade - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
@ -13,59 +13,112 @@ CFG=mysql_upgrade - Win32 Release
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "mysql_upgrade.mak" CFG="mysql_upgrade - Win32 Release"
!MESSAGE NMAKE /f "mysql_upgrade.mak" CFG="mysql_upgrade - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "mysql_upgrade - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "mysql_upgrade - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE "mysql_upgrade - Win32 classic" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
CPP=xicl6.exe
RSC=rc.exe
!IF "$(CFG)" == "mysql_upgrade - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "mysql_upgrade___Win32_Release"
# PROP BASE Intermediate_Dir "mysql_upgrade___Win32_Release"
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "mysql_upgrade___Win32_Release"
# PROP Intermediate_Dir "mysql_upgrade___Win32_Release"
# PROP Output_Dir "release"
# PROP Intermediate_Dir "release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /G6 /MT /W3 /O2 /I "../include" /D "NDEBUG" /D "DBUG_OFF" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /Fp"Release/mysql_upgrade.pch" /YX /Fo"Release/" /Fd"Release/" /FD /c
# ADD BASE RSC /l 0x416 /d "NDEBUG"
# ADD RSC /l 0x416 /d "NDEBUG"
# ADD CPP /nologo /G6 /MT /W3 /O2 /I "../include" /I "../" /D "DBUG_OFF" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /D "NDEBUG" /FD /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 mysqlclient.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib zlib.lib /nologo /subsystem:console /pdb:"release/mysql_upgrade.pdb" /machine:I386 /out:"../client_release/mysql_upgrade.exe" /libpath:"..\lib_release\\"
# SUBTRACT LINK32 /pdb:none
LINK32=xilink6.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 mysqlclient.lib mysys.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib zlib.lib ..\extra\yassl\Release\yassl.lib /nologo /subsystem:console /machine:I386 /out:"../client_release/mysql_upgrade.exe" /libpath:"..\lib_release\\"
# SUBTRACT LINK32 /incremental:yes
!ELSEIF "$(CFG)" == "mysql_upgrade - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "mysqlimp"
# PROP BASE Intermediate_Dir "mysqlimp"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "debug"
# PROP Intermediate_Dir "debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /G6 /MTd /W3 /Z7 /Od /I "../include" /I "../" /D "_DEBUG" /D "SAFEMALLOC" /D "SAFE_MUTEX" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /FD /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=xilink6.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 mysqlclient.lib mysys.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib zlib.lib setargv.obj ..\extra\yassl\Debug\yassl.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../client_debug/mysql_upgrade.exe" /pdbtype:sept /libpath:"..\lib_debug\\"
!ELSEIF "$(CFG)" == "mysql_upgrade - Win32 classic"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "mysql_upgrade___Win32_classic"
# PROP BASE Intermediate_Dir "mysql_upgrade___Win32_classic"
# PROP BASE Ignore_Export_Lib 0
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "classic"
# PROP Intermediate_Dir "classic"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /G6 /MT /W3 /O2 /I "../include" /I "../" /D "DBUG_OFF" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /D "NDEBUG" /FD /c
# SUBTRACT BASE CPP /YX
# ADD CPP /nologo /G6 /MT /W3 /O2 /I "../include" /I "../" /D "_CONSOLE" /D "_WINDOWS" /D LICENSE=Commercial /D "DBUG_OFF" /D "_MBCS" /D "NDEBUG" /FD /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=xilink6.exe
# ADD BASE LINK32 mysqlclient.lib mysys.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"../client_release/mysql_upgrade.exe" /libpath:"..\lib_release\\"
# SUBTRACT BASE LINK32 /incremental:yes
# ADD LINK32 mysqlclient.lib mysys.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib zlib.lib ..\extra\yassl\Release\yassl.lib /nologo /subsystem:console /machine:I386 /out:"../client_classic/mysql_upgrade.exe" /libpath:"..\lib_release\\"
# SUBTRACT LINK32 /incremental:yes
!ENDIF
# Begin Target
# Name "mysql_upgrade - Win32 Release"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Name "mysql_upgrade - Win32 Debug"
# Name "mysql_upgrade - Win32 classic"
# Begin Source File
SOURCE=.\mysql_upgrade.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

View File

@ -0,0 +1,232 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="mysql_upgrade"
SccProjectName=""
SccLocalPath="">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\debug"
IntermediateDirectory=".\debug"
ConfigurationType="1"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
OptimizeForProcessor="2"
AdditionalIncludeDirectories="../include,../"
PreprocessorDefinitions="_DEBUG;SAFEMALLOC;SAFE_MUTEX;_CONSOLE;_WINDOWS"
RuntimeLibrary="1"
PrecompiledHeaderFile=".\debug/mysql_upgrade.pch"
AssemblerListingLocation=".\debug/"
ObjectFile=".\debug/"
ProgramDataBaseFileName=".\debug/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="1"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="wsock32.lib odbc32.lib odbccp32.lib setargv.obj"
OutputFile="../client_debug/mysql_upgrade.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories=""
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\debug/mysql_upgrade.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\debug/mysql_upgrade.tlb"
HeaderFileName=""/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory=".\release"
IntermediateDirectory=".\release"
ConfigurationType="1"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
OptimizeForProcessor="2"
AdditionalIncludeDirectories="../include,../"
PreprocessorDefinitions="DBUG_OFF;_CONSOLE;_WINDOWS;NDEBUG"
StringPooling="TRUE"
RuntimeLibrary="0"
EnableFunctionLevelLinking="TRUE"
PrecompiledHeaderFile=".\release/mysql_upgrade.pch"
AssemblerListingLocation=".\release/"
ObjectFile=".\release/"
ProgramDataBaseFileName=".\release/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="wsock32.lib odbc32.lib odbccp32.lib"
OutputFile="../client_release/mysql_upgrade.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories=""
ProgramDatabaseFile=".\release/mysql_upgrade.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\release/mysql_upgrade.tlb"
HeaderFileName=""/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="classic|Win32"
OutputDirectory=".\classic"
IntermediateDirectory=".\classic"
ConfigurationType="1"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
OptimizeForProcessor="2"
AdditionalIncludeDirectories="../include,../"
PreprocessorDefinitions="_CONSOLE;_WINDOWS;LICENSE=Commercial;DBUG_OFF;NDEBUG"
StringPooling="TRUE"
RuntimeLibrary="0"
EnableFunctionLevelLinking="TRUE"
PrecompiledHeaderFile=".\classic/mysql_upgrade.pch"
AssemblerListingLocation=".\classic/"
ObjectFile=".\classic/"
ProgramDataBaseFileName=".\classic/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="wsock32.lib odbc32.lib odbccp32.lib"
OutputFile="../client_classic/mysql_upgrade.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories=""
ProgramDatabaseFile=".\classic/mysql_upgrade.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\classic/mysql_upgrade.tlb"
HeaderFileName=""/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<File
RelativePath="mysql_upgrade.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="classic|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -4,20 +4,22 @@
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=mysql_upgrade - Win32 Release
CFG=mysql_upgrade - WinIA64 classic
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "mysql_upgrade.mak".
!MESSAGE NMAKE /f "mysql_upgrade_ia64.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "mysql_upgrade.mak" CFG="mysql_upgrade - Win32 Release"
!MESSAGE NMAKE /f "mysql_upgrade_ia64.mak" CFG="mysql_upgrade - WinIA64 classic"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "mysql_upgrade - WinIA64 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "mysql_upgrade - WinIA64 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE "mysql_upgrade - WinIA64 classic" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
@ -27,51 +29,96 @@ CFG=mysql_upgrade - Win32 Release
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "mysql - WinIA64 Release"
!IF "$(CFG)" == "mysql_upgrade - WinIA64 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "mysql_upgrade___WinIA64_Release"
# PROP BASE Intermediate_Dir "mysql_upgrade___WinIA64_Release"
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "mysql_upgrade___WinIA64_Release"
# PROP Intermediate_Dir "mysql_upgrade___WinIA64_Release"
# PROP Output_Dir "release"
# PROP Intermediate_Dir "release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
MTL=midl.exe
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN64" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /I "../include" /D"NDEBUG" /D"DBUG_OFF" /D"_CONSOLE" /D"_MBCS" /D"_WINDOWS" /Fp"Release/mysql_upgrade.pch" /YX /Fo"Release/" /Fd"Release/" /FD /c /O2 /G2 /EHsc /D"_IA64_" /Zi /D"WIN64" /D"WIN32" /D"_AFX_NO_DAO_SUPPORT" /Wp64 /Zm600
# ADD BASE RSC /l 0x416 /d "NDEBUG"
# ADD RSC /l 0x416 /d "NDEBUG"
# ADD CPP /nologo /MT /W3 /Zi /O2 /I "../include" /I "../" /D "DBUG_OFF" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /D "NDEBUG" /D "_IA64_" /D "WIN64" /D "WIN32" /D "_AFX_NO_DAO_SUPPORT" /FD /G2 /EHsc /Wp64 /Zm600 /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:IA64
# ADD LINK32 mysqlclient.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib zlib.lib /nologo /subsystem:console /pdb:"release/mysql_upgrade.pdb" /machine:IA64 /out:"../client_release/mysql_upgrade.exe" /libpath:"..\lib_release\\" /incremental:no
# SUBTRACT LINK32
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:IA64
# ADD LINK32 ..\lib_release\zlib.lib mysqlclient.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib bufferoverflowU.lib zlib.lib /nologo /subsystem:console /out:"../client_release/mysql_upgrade.exe" /libpath:"..\lib_release\\" /machine:IA64
!ELSEIF "$(CFG)" == "mysql_upgrade - WinIA64 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "mysqlimp"
# PROP BASE Intermediate_Dir "mysqlimp"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "debug"
# PROP Intermediate_Dir "debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
MTL=midl.exe
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN64" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MTd /W3 /Zi /Od /I "../include" /I "../" /D "_DEBUG" /D "SAFEMALLOC" /D "SAFE_MUTEX" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /D "_IA64_" /D "WIN64" /D "WIN32" /D "_AFX_NO_DAO_SUPPORT" /FD /G2 /EHsc /Wp64 /Zm600 /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:IA64
# ADD LINK32 setargv.obj ..\lib_debug\zlib.lib ..\lib_debug\dbug.lib mysqlclient.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib bufferoverflowU.lib zlib.lib /nologo /subsystem:console /incremental:no /debug /out:"../client_debug/mysql_upgrade.exe" /libpath:"..\lib_debug\\" /machine:IA64
!ELSEIF "$(CFG)" == "mysql_upgrade - WinIA64 classic"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "mysql_upgrade___WinIA64_classic"
# PROP BASE Intermediate_Dir "mysql_upgrade___WinIA64_classic"
# PROP BASE Ignore_Export_Lib 0
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "classic"
# PROP Intermediate_Dir "classic"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
MTL=midl.exe
# ADD BASE CPP /nologo /G6 /MT /W3 /O2 /I "../include" /I "../" /D "DBUG_OFF" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /D "NDEBUG" /FD /c
# SUBTRACT BASE CPP /YX
# ADD CPP /nologo /MT /W3 /Zi /O2 /I "../include" /I "../" /D "_CONSOLE" /D "_WINDOWS" /D LICENSE=Commercial /D "DBUG_OFF" /D "_MBCS" /D "NDEBUG" /D "_IA64_" /D "WIN64" /D "WIN32" /D "_AFX_NO_DAO_SUPPORT" /FD /G2 /EHsc /Wp64 /Zm600 /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 mysqlclient.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /out:"../client_release/mysql_upgrade.exe" /libpath:"..\lib_release\\" /machine:IA64
# ADD LINK32 ..\lib_release\zlib.lib mysqlclient.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib bufferoverflowU.lib zlib.lib /nologo /subsystem:console /out:"../client_classic/mysql_upgrade.exe" /libpath:"..\lib_release\\" /machine:IA64
!ENDIF
# Begin Target
# Name "mysql_upgrade - WinIA64 Release"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Name "mysql_upgrade - WinIA64 Debug"
# Name "mysql_upgrade - WinIA64 classic"
# Begin Source File
SOURCE=.\mysql_upgrade.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

View File

@ -446,6 +446,9 @@ Package=<4>
Project_Dep_Name mysqlimport
End Project Dependency
Begin Project Dependency
Project_Dep_Name mysql_upgrade
End Project Dependency
Begin Project Dependency
Project_Dep_Name mysqlshow
End Project Dependency
Begin Project Dependency
@ -530,6 +533,24 @@ Package=<4>
###############################################################################
Project: "mysql_upgrade"=".\client\mysql_upgade.dsp" - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name mysqlclient
End Project Dependency
Begin Project Dependency
Project_Dep_Name mysys
End Project Dependency
}}}
###############################################################################
Project: "mysqlserver"=".\mysqlserver\mysqlserver.dsp" - Package Owner=<4>
Package=<5>

View File

@ -157,6 +157,14 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mysqlimport", "client\mysql
{44D9C7DC-6636-4B82-BD01-6876C64017DF} = {44D9C7DC-6636-4B82-BD01-6876C64017DF}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mysql_upgrade", "client\mysql_upgrade.vcproj", "{AD95DAD3-6DB9-4F8B-A345-7A39A83AAD3D}"
ProjectSection(ProjectDependencies) = postProject
{BA86AE72-0CF5-423D-BBA2-E12B0D72EBFB} = {BA86AE72-0CF5-423D-BBA2-E12B0D72EBFB}
{26383276-4843-494B-8BE0-8936ED3EBAAB} = {26383276-4843-494B-8BE0-8936ED3EBAAB}
{8762A9B8-72A9-462E-A9A2-F3265081F8AF} = {8762A9B8-72A9-462E-A9A2-F3265081F8AF}
{44D9C7DC-6636-4B82-BD01-6876C64017DF} = {44D9C7DC-6636-4B82-BD01-6876C64017DF}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mysqlserver", "mysqlserver\mysqlserver.vcproj", "{94B86159-C581-42CD-825D-C69CBC237E5C}"
ProjectSection(ProjectDependencies) = postProject
{EEC1300B-85A5-497C-B3E1-F708021DF859} = {EEC1300B-85A5-497C-B3E1-F708021DF859}

View File

@ -528,6 +528,9 @@ Package=<4>
Project_Dep_Name mysqlimport
End Project Dependency
Begin Project Dependency
Project_Dep_Name mysql_upgrade
End Project Dependency
Begin Project Dependency
Project_Dep_Name mysqlshow
End Project Dependency
Begin Project Dependency
@ -600,6 +603,21 @@ Package=<4>
###############################################################################
Project: "mysql_upgrade"=".\client\mysql_upgrade_ia64.dsp" - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name mysqlclient
End Project Dependency
}}}
###############################################################################
Project: "mysqlserver"=".\mysqlserver\mysqlserver_ia64.dsp" - Package Owner=<4>
Package=<5>

View File

@ -1,6 +1,7 @@
AC_DEFUN([MYSQL_FIND_OPENSSL], [
incs="$1"
libs="$2"
eval shrexts=\"$shrext_cmds\"
case "$incs---$libs" in
---)
for d in /usr/ssl/include /usr/local/ssl/include /usr/include \
@ -15,7 +16,7 @@ AC_DEFUN([MYSQL_FIND_OPENSSL], [
/usr/lib /usr/lib64 /opt/ssl/lib /opt/openssl/lib \
/usr/freeware/lib32 /usr/local/lib/ ; do
# Just to be safe, we test for ".so" anyway
if test -f $d/libssl.a || test -f $d/libssl.so || test -f $d/libssl$shrext_cmds ; then
if test -f $d/libssl.a || test -f $d/libssl.so || test -f $d/libssl$shrext ; then
OPENSSL_LIB=$d
fi
done
@ -28,7 +29,7 @@ AC_DEFUN([MYSQL_FIND_OPENSSL], [
OPENSSL_INCLUDE=-I$incs
fi
# Just to be safe, we test for ".so" anyway
if test -f $libs/libssl.a || test -f $libs/libssl.so || test -f $libs/libssl$shrext_cmds ; then
if test -f $libs/libssl.a || test -f $libs/libssl.so || test -f $libs/libssl$shrext ; then
OPENSSL_LIB=$libs
fi
;;

View File

@ -90,8 +90,9 @@ case $SYSTEM_TYPE in
;;
*)
# Just to be safe, we test for ".so" anyway
eval shrexts=\"$shrext_cmds\"
if test \( -f "$mysql_zlib_dir/lib/libz.a" -o -f "$mysql_zlib_dir/lib/libz.so" -o \
-f "$mysql_zlib_dir/lib/libz$shrext_cmds" \) \
-f "$mysql_zlib_dir/lib/libz$shrext" \) \
-a -f "$mysql_zlib_dir/include/zlib.h"; then
ZLIB_INCLUDES="-I$mysql_zlib_dir/include"
ZLIB_LIBS="-L$mysql_zlib_dir/lib -lz"

View File

@ -196,6 +196,7 @@ then
else
AC_PATH_PROG(AS, as, as)
fi
# Still need ranlib for readline; local static use only so no libtool.
AC_PROG_RANLIB
# We use libtool
@ -207,6 +208,13 @@ AC_PROG_LIBTOOL
LIBTOOL="$LIBTOOL --preserve-dup-deps"
AC_SUBST(LIBTOOL)dnl
AC_SUBST(NM)dnl
# NM= "$NM -X64"
#archive_expsym_cmds= `echo "$archive_expsym_cmds" | sed -e '/"$(CC)"//'`
#archive_expsym_cmds= "$CC -q64 $archive_expsym_cmds"
# CXXFLAGS=`echo "$CXXFLAGS -Werror" | sed -e 's/-fbranch-probabilities//; s/-Wall//; s/-ansi//; s/-pedantic//; s/-Wcheck//'`
#AC_LIBTOOL_DLOPEN AC_LIBTOOL_WIN32_DLL AC_DISABLE_FAST_INSTALL AC_DISABLE_SHARED AC_DISABLE_STATIC
# AC_PROG_INSTALL
@ -482,7 +490,7 @@ then
AC_MSG_ERROR([MySQL requires an ANSI C compiler (and a C++ compiler). Try gcc. See the Installation chapter in the Reference Manual.])
fi
NOINST_LDFLAGS=
NOINST_LDFLAGS="-static"
static_nss=""
STATIC_NSS_FLAGS=""
@ -705,9 +713,8 @@ AC_CHECK_FUNC(yp_get_default_domain, ,
AC_CHECK_FUNC(p2open, , AC_CHECK_LIB(gen, p2open))
# This may get things to compile even if bind-8 is installed
AC_CHECK_FUNC(bind, , AC_CHECK_LIB(bind, bind))
# For crypt() on Linux
AC_CHECK_LIB(crypt, crypt)
AC_CHECK_FUNC(crypt, AC_DEFINE([HAVE_CRYPT], [1], [crypt]))
# Check if crypt() exists in libc or libcrypt, sets LIBS if needed
AC_SEARCH_LIBS(crypt, crypt, AC_DEFINE(HAVE_CRYPT, 1, [crypt]))
# For sem_xxx functions on Solaris 2.6
AC_CHECK_FUNC(sem_init, , AC_CHECK_LIB(posix4, sem_init))

View File

@ -1,3 +1,3 @@
SUBDIRS = taocrypt src
SUBDIRS = taocrypt src testsuite
EXTRA_DIST = yassl.dsp yassl.dsw yassl.vcproj $(wildcard mySTL/*.hpp) \
cmakelists.txt

View File

@ -1,4 +1,137 @@
yaSSL Release notes, version 0.9.6
yaSSL Release notes, version 1.2.2 (03/27/06)
This release of yaSSL contains minor bug fixes and portability enhancements.
See build instructions below under 1.0.6:
*******************yaSSL Release notes, version 1.2.0
This release of yaSSL contains minor bug fixes, portability enhancements,
Diffie-Hellman compatibility fixes for other servers and client,
optimization improvements, and x86 ASM changes.
See build instructions below under 1.0.6:
*****************yaSSL Release notes, version 1.1.5
This release of yaSSL contains minor bug fixes, portability enhancements,
and user requested changes including the ability to add all certificates in
a directory, more robust socket handling, no new overloading unless
requested, and an SSL_VERIFY_NONE option.
See build instructions below under 1.0.6:
******************yaSSL Release notes, version 1.0.6
This release of yaSSL contains minor bug fixes, portability enhancements,
x86 assembly for ARC4, SHA, MD5, and RIPEMD, --enable-ia32-asm configure
option, and a security patch for certificate chain processing.
--To build on Linux, Solaris, *BSD, Mac OS X, or Cygwin:
./configure
make
run testsuite from yaSSL-Home/testsuite to test the build
to make a release build:
./configure --disable-debug
make
run testsuite from yaSSL-Home/testsuite to test the build
--To build on Win32
Choose (Re)Build All from the project workspace
run Debug\testsuite.exe from yaSSL-Home\testsuite to test the build
--To enable ia32 assembly for TaoCrypt ciphers and message digests
On MSVC this is always on
On GCC **, use ./configure --enable-ia32-asm
** This isn't on by default because of the use of intel syntax and the
problem that olders versions of gas have with some addressing statements.
If you enable this and get assemler errors during compilation or can't
pass the TaoCrypt tests, please send todd@yassl.com a message and disable
this option in the meantime.
***************** yaSSL Release notes, version 1.0.5
This release of yaSSL contains minor bug fixes, portability enhancements,
x86 assembly for AES, 3DES, BLOWFISH, and TWOFISH, --without-debug configure
option, and --enable-kernel-mode configure option for using TaoCrypt with
kernel modules.
--To build on Linux, Solaris, *BSD, Mac OS X, or Cygwin:
./configure
make
run testsuite from yaSSL-Home/testsuite to test the build
to make a release build:
./configure --without-debug
make
run testsuite from yaSSL-Home/testsuite to test the build
--To build on Win32
Choose (Re)Build All from the project workspace
run Debug\testsuite.exe from yaSSL-Home\testsuite to test the build
******************yaSSL Release notes, version 1.0.1
This release of yaSSL contains minor bug fixes, portability enhancements,
GCC 3.4.4 support, MSVC 2003 support, and more documentation.
Please see build instructions in the release notes for 0.9.6 below.
******************yaSSL Release notes, version 1.0
This release of yaSSL contains minor bug fixes, portability enhancements,
GCC 4.0 support, testsuite, improvements, and API additions.
Please see build instructions in the release notes for 0.9.6 below.
******************yaSSL Release notes, version 0.9.9
This release of yaSSL contains minor bug fixes, portability enchancements,
MSVC 7 support, memory improvements, and API additions.
Please see build instructions in the release notes for 0.9.6 below.
******************yaSSL Release notes, version 0.9.8
This release of yaSSL contains minor bug fixes and portability enchancements.
Please see build instructions in the release notes for 0.9.6 below.
******************yaSSL Release notes, version 0.9.6
This release of yaSSL contains minor bug fixes, removal of STL support, and
removal of exceptions and rtti so that the library can be linked without the

View File

@ -0,0 +1,96 @@
/* client.cpp */
#include "../../testsuite/test.hpp"
//#define TEST_RESUME
void client_test(void* args)
{
#ifdef _WIN32
WSADATA wsd;
WSAStartup(0x0002, &wsd);
#endif
SOCKET_T sockfd = 0;
int argc = 0;
char** argv = 0;
set_args(argc, argv, *static_cast<func_args*>(args));
tcp_connect(sockfd);
SSL_METHOD* method = TLSv1_client_method();
SSL_CTX* ctx = SSL_CTX_new(method);
set_certs(ctx);
SSL* ssl = SSL_new(ctx);
SSL_set_fd(ssl, sockfd);
if (SSL_connect(ssl) != SSL_SUCCESS) err_sys("SSL_connect failed");
showPeer(ssl);
const char* cipher = 0;
int index = 0;
char list[1024];
strcpy(list, "cipherlist");
while ( (cipher = SSL_get_cipher_list(ssl, index++)) ) {
strcat(list, ":");
strcat(list, cipher);
}
printf("%s\n", list);
printf("Using Cipher Suite %s\n", SSL_get_cipher(ssl));
char msg[] = "hello yassl!";
if (SSL_write(ssl, msg, sizeof(msg)) != sizeof(msg))
err_sys("SSL_write failed");
char reply[1024];
reply[SSL_read(ssl, reply, sizeof(reply))] = 0;
printf("Server response: %s\n", reply);
#ifdef TEST_RESUME
SSL_SESSION* session = SSL_get_session(ssl);
SSL* sslResume = SSL_new(ctx);
#endif
SSL_shutdown(ssl);
SSL_free(ssl);
#ifdef TEST_RESUME
tcp_connect(sockfd);
SSL_set_fd(sslResume, sockfd);
SSL_set_session(sslResume, session);
if (SSL_connect(sslResume) != SSL_SUCCESS) err_sys("SSL resume failed");
if (SSL_write(sslResume, msg, sizeof(msg)) != sizeof(msg))
err_sys("SSL_write failed");
reply[SSL_read(sslResume, reply, sizeof(reply))] = 0;
printf("Server response: %s\n", reply);
SSL_shutdown(sslResume);
SSL_free(sslResume);
#endif // TEST_RESUME
SSL_CTX_free(ctx);
((func_args*)args)->return_code = 0;
}
#ifndef NO_MAIN_DRIVER
int main(int argc, char** argv)
{
func_args args;
args.argc = argc;
args.argv = argv;
client_test(&args);
return args.return_code;
}
#endif // NO_MAIN_DRIVER

View File

@ -0,0 +1,102 @@
# Microsoft Developer Studio Project File - Name="client" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=client - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "client.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "client.mak" CFG="client - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "client - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "client - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "client - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /O2 /I "..\..\taocrypt\include" /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "client - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /I "..\..\include" /I "..\..\taocrypt\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "client - Win32 Release"
# Name "client - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\client.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

View File

@ -0,0 +1,89 @@
/* echoclient.cpp */
#include "../../testsuite/test.hpp"
void echoclient_test(void* args)
{
#ifdef _WIN32
WSADATA wsd;
WSAStartup(0x0002, &wsd);
#endif
SOCKET_T sockfd = 0;
int argc = 0;
char** argv = 0;
FILE* fin = stdin;
FILE* fout = stdout;
bool inCreated = false;
bool outCreated = false;
set_args(argc, argv, *static_cast<func_args*>(args));
if (argc >= 2) {
fin = fopen(argv[1], "r");
inCreated = true;
}
if (argc >= 3) {
fout = fopen(argv[2], "w");
outCreated = true;
}
if (!fin) err_sys("can't open input file");
if (!fout) err_sys("can't open output file");
tcp_connect(sockfd);
SSL_METHOD* method = TLSv1_client_method();
SSL_CTX* ctx = SSL_CTX_new(method);
set_certs(ctx);
SSL* ssl = SSL_new(ctx);
SSL_set_fd(ssl, sockfd);
if (SSL_connect(ssl) != SSL_SUCCESS) err_sys("SSL_connect failed");
char send[1024];
char reply[1024];
while (fgets(send, sizeof(send), fin)) {
int sendSz = strlen(send) + 1;
if (SSL_write(ssl, send, sendSz) != sendSz)
err_sys("SSL_write failed");
if (strncmp(send, "quit", 4) == 0) {
fputs("sending server shutdown command: quit!\n", fout);
break;
}
if (SSL_read(ssl, reply, sizeof(reply)) > 0)
fputs(reply, fout);
}
SSL_CTX_free(ctx);
SSL_free(ssl);
fflush(fout);
if (inCreated) fclose(fin);
if (outCreated) fclose(fout);
((func_args*)args)->return_code = 0;
}
#ifndef NO_MAIN_DRIVER
int main(int argc, char** argv)
{
func_args args;
args.argc = argc;
args.argv = argv;
echoclient_test(&args);
return args.return_code;
}
#endif // NO_MAIN_DRIVER

View File

@ -0,0 +1,102 @@
# Microsoft Developer Studio Project File - Name="echoclient" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=echoclient - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "echoclient.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "echoclient.mak" CFG="echoclient - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "echoclient - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "echoclient - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "echoclient - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /O2 /I "..\..\include" /I "..\..\taocrypt\include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "echoclient - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /I "..\..\include" /I "..\..\taocrypt\include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "echoclient - Win32 Release"
# Name "echoclient - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\echoclient.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

View File

@ -0,0 +1,93 @@
/* echoclient.cpp */
#include "openssl/ssl.h" /* openssl compatibility test */
#include <stdio.h>
#include <stdlib.h>
#ifdef WIN32
#include <winsock2.h>
#else
#include <string.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#endif /* WIN32 */
void err_sys(const char* msg)
{
fputs("yassl client error: ", stderr);
fputs(msg, stderr);
exit(EXIT_FAILURE);
}
const char* loopback = "127.0.0.1";
const short yasslPort = 11111;
using namespace yaSSL;
int main(int argc, char** argv)
{
#ifdef WIN32
WSADATA wsd;
WSAStartup(0x0002, &wsd);
int sockfd;
#else
unsigned int sockfd;
#endif /* WIN32 */
FILE* fin = stdin;
FILE* fout = stdout;
if (argc >= 2) fin = fopen(argv[1], "r");
if (argc >= 3) fout = fopen(argv[2], "w");
if (!fin) err_sys("can't open input file");
if (!fout) err_sys("can't open output file");
sockfd = socket(AF_INET, SOCK_STREAM, 0);
sockaddr_in servaddr;
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(yasslPort);
servaddr.sin_addr.s_addr = inet_addr(loopback);
if (connect(sockfd, (const sockaddr*)&servaddr, sizeof(servaddr)) != 0)
err_sys("tcp connect failed");
SSL_METHOD* method = TLSv1_client_method();
SSL_CTX* ctx = SSL_CTX_new(method);
SSL* ssl = SSL_new(ctx);
SSL_set_fd(ssl, sockfd);
if (SSL_connect(ssl) != SSL_SUCCESS) err_sys("SSL_connect failed");
char send[1024];
char reply[1024];
while (fgets(send, sizeof(send), fin)) {
int sendSz = strlen(send) + 1;
if (SSL_write(ssl, send, sendSz) != sendSz)
err_sys("SSL_write failed");
if (strncmp(send, "quit", 4) == 0) {
fputs("sending server shutdown command: quit!", fout);
break;
}
if (SSL_read(ssl, reply, sizeof(reply)) > 0)
fputs(reply, fout);
}
SSL_CTX_free(ctx);
SSL_free(ssl);
return 0;
}

View File

@ -0,0 +1,2 @@
quit

View File

@ -0,0 +1,126 @@
/* echoserver.cpp */
#include "../../testsuite/test.hpp"
#ifndef NO_MAIN_DRIVER
#define ECHO_OUT
THREAD_RETURN YASSL_API echoserver_test(void*);
int main(int argc, char** argv)
{
func_args args;
args.argc = argc;
args.argv = argv;
echoserver_test(&args);
return args.return_code;
}
#endif // NO_MAIN_DRIVER
THREAD_RETURN YASSL_API echoserver_test(void* args)
{
#ifdef _WIN32
WSADATA wsd;
WSAStartup(0x0002, &wsd);
#endif
SOCKET_T sockfd = 0;
int argc = 0;
char** argv = 0;
set_args(argc, argv, *static_cast<func_args*>(args));
#ifdef ECHO_OUT
FILE* fout = stdout;
if (argc >= 2) fout = fopen(argv[1], "w");
if (!fout) err_sys("can't open output file");
#endif
tcp_listen(sockfd);
SSL_METHOD* method = TLSv1_server_method();
SSL_CTX* ctx = SSL_CTX_new(method);
set_serverCerts(ctx);
DH* dh = set_tmpDH(ctx);
bool shutdown(false);
#if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER)
// signal ready to tcp_accept
func_args& server_args = *((func_args*)args);
tcp_ready& ready = *server_args.signal_;
pthread_mutex_lock(&ready.mutex_);
ready.ready_ = true;
pthread_cond_signal(&ready.cond_);
pthread_mutex_unlock(&ready.mutex_);
#endif
while (!shutdown) {
sockaddr_in client;
socklen_t client_len = sizeof(client);
int clientfd = accept(sockfd, (sockaddr*)&client, &client_len);
if (clientfd == -1) err_sys("tcp accept failed");
SSL* ssl = SSL_new(ctx);
SSL_set_fd(ssl, clientfd);
if (SSL_accept(ssl) != SSL_SUCCESS) err_sys("SSL_accept failed");
char command[1024];
int echoSz(0);
while ( (echoSz = SSL_read(ssl, command, sizeof(command))) > 0) {
if ( strncmp(command, "quit", 4) == 0) {
printf("client sent quit command: shutting down!\n");
shutdown = true;
break;
}
else if ( strncmp(command, "GET", 3) == 0) {
char type[] = "HTTP/1.0 200 ok\r\nContent-type:"
" text/html\r\n\r\n";
char header[] = "<html><body BGCOLOR=\"#ffffff\">\n<pre>\n";
char body[] = "greetings from yaSSL\n";
char footer[] = "</body></html>\r\n\r\n";
strncpy(command, type, sizeof(type));
echoSz = sizeof(type) - 1;
strncpy(&command[echoSz], header, sizeof(header));
echoSz += sizeof(header) - 1;
strncpy(&command[echoSz], body, sizeof(body));
echoSz += sizeof(body) - 1;
strncpy(&command[echoSz], footer, sizeof(footer));
echoSz += sizeof(footer);
if (SSL_write(ssl, command, echoSz) != echoSz)
err_sys("SSL_write failed");
break;
}
command[echoSz] = 0;
#ifdef ECHO_OUT
fputs(command, fout);
#endif
if (SSL_write(ssl, command, echoSz) != echoSz)
err_sys("SSL_write failed");
}
SSL_free(ssl);
}
#ifdef _WIN32
closesocket(sockfd);
#else
close(sockfd);
#endif
DH_free(dh);
SSL_CTX_free(ctx);
((func_args*)args)->return_code = 0;
return 0;
}

View File

@ -0,0 +1,102 @@
# Microsoft Developer Studio Project File - Name="echoserver" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=echoserver - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "echoserver.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "echoserver.mak" CFG="echoserver - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "echoserver - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "echoserver - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "echoserver - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /G6 /MT /W3 /O2 /I "..\..\include" /I "..\..\taocrypt\include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "echoserver - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /I "..\..\include" /I "..\..\taocrypt\include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "echoserver - Win32 Release"
# Name "echoserver - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\echoserver.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

View File

@ -0,0 +1,73 @@
/* server.cpp */
#include "../../testsuite/test.hpp"
THREAD_RETURN YASSL_API server_test(void* args)
{
#ifdef _WIN32
WSADATA wsd;
WSAStartup(0x0002, &wsd);
#endif
SOCKET_T sockfd = 0;
int clientfd = 0;
int argc = 0;
char** argv = 0;
set_args(argc, argv, *static_cast<func_args*>(args));
tcp_accept(sockfd, clientfd, *static_cast<func_args*>(args));
#ifdef _WIN32
closesocket(sockfd);
#else
close(sockfd);
#endif
SSL_METHOD* method = TLSv1_server_method();
SSL_CTX* ctx = SSL_CTX_new(method);
//SSL_CTX_set_cipher_list(ctx, "RC4-SHA");
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
set_serverCerts(ctx);
DH* dh = set_tmpDH(ctx);
SSL* ssl = SSL_new(ctx);
SSL_set_fd(ssl, clientfd);
if (SSL_accept(ssl) != SSL_SUCCESS) err_sys("SSL_accept failed");
showPeer(ssl);
printf("Using Cipher Suite %s\n", SSL_get_cipher(ssl));
char command[1024];
command[SSL_read(ssl, command, sizeof(command))] = 0;
printf("First client command: %s\n", command);
char msg[] = "I hear you, fa shizzle!";
if (SSL_write(ssl, msg, sizeof(msg)) != sizeof(msg))
err_sys("SSL_write failed");
DH_free(dh);
SSL_CTX_free(ctx);
SSL_free(ssl);
((func_args*)args)->return_code = 0;
return 0;
}
#ifndef NO_MAIN_DRIVER
int main(int argc, char** argv)
{
func_args args;
args.argc = argc;
args.argv = argv;
server_test(&args);
return args.return_code;
}
#endif // NO_MAIN_DRIVER

View File

@ -0,0 +1,109 @@
# Microsoft Developer Studio Project File - Name="server" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=server - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "server.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "server.mak" CFG="server - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "server - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "server - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "server - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /O2 /I "..\..\include" /I "..\..\taocrypt\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /machine:I386
# SUBTRACT LINK32 /pdb:none
!ELSEIF "$(CFG)" == "server - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /I "..\..\include" /I "..\..\taocrypt\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /FR /YX /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# SUBTRACT LINK32 /pdb:none /nodefaultlib
!ENDIF
# Begin Target
# Name "server - Win32 Release"
# Name "server - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\server.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

View File

@ -83,6 +83,7 @@ class CertManager {
SignerList signers_; // decoded CA keys and names
// plus verified chained certs
bool verifyPeer_;
bool verifyNone_; // no error if verify fails
bool failNoCert_;
bool sendVerify_;
public:
@ -107,10 +108,12 @@ public:
uint get_privateKeyLength() const;
bool verifyPeer() const;
bool verifyNone() const;
bool failNoCert() const;
bool sendVerify() const;
void setVerifyPeer();
void setVerifyNone();
void setFailNoCert();
void setSendVerify();
private:

View File

@ -41,8 +41,8 @@
namespace yaSSL {
// Digest policy should implement a get_digest, update, and get sizes for pad and
// digest
// Digest policy should implement a get_digest, update, and get sizes for pad
// and digest
struct Digest : public virtual_base {
virtual void get_digest(byte*) = 0;
virtual void get_digest(byte*, const byte*, unsigned int) = 0;
@ -380,7 +380,7 @@ public:
uint get_agreedKeyLength() const;
const byte* get_agreedKey() const;
const byte* get_publicKey() const;
void makeAgreement(const byte*);
void makeAgreement(const byte*, unsigned int);
void set_sizes(int&, int&, int&) const;
void get_parms(byte*, byte*, byte*) const;

View File

@ -23,6 +23,8 @@
*
*/
#ifndef yaSSL_openssl_h__
#define yaSSL_openssl_h__
@ -49,7 +51,7 @@ extern "C" {
class X509_NAME;
#else
typedef struct SSL SSL;
typedef struct SSL_SESION SSL_SESSION;
typedef struct SSL_SESSION SSL_SESSION;
typedef struct SSL_METHOD SSL_METHOD;
typedef struct SSL_CTX SSL_CTX;
typedef struct SSL_CIPHER SSL_CIPHER;
@ -258,6 +260,8 @@ int SSL_pending(SSL*);
enum { /* ssl Constants */
SSL_BAD_STAT = -7,
SSL_BAD_PATH = -6,
SSL_BAD_FILETYPE = -5,
SSL_BAD_FILE = -4,
SSL_NOT_IMPLEMENTED = -3,

View File

@ -77,7 +77,7 @@ public:
uint send(const byte* buf, unsigned int len, int flags = 0) const;
uint receive(byte* buf, unsigned int len, int flags = 0) const;
void wait() const;
bool wait() const;
void closeSocket();
void shutDown(int how = SD_SEND);

View File

@ -0,0 +1,88 @@
/* yassl.hpp
*
* Copyright (C) 2003 Sawtooth Consulting Ltd.
*
* This file is part of yaSSL.
*
* yaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* yaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/* yaSSL externel header defines yaSSL API
*/
#ifndef yaSSL_EXT_HPP
#define yaSSL_EXT_HPP
namespace yaSSL {
#ifdef _WIN32
typedef unsigned int SOCKET_T;
#else
typedef int SOCKET_T;
#endif
class Client {
public:
Client();
~Client();
// basics
int Connect(SOCKET_T);
int Write(const void*, int);
int Read(void*, int);
// options
void SetCA(const char*);
void SetCert(const char*);
void SetKey(const char*);
private:
struct ClientImpl;
ClientImpl* pimpl_;
Client(const Client&); // hide copy
Client& operator=(const Client&); // and assign
};
class Server {
public:
Server();
~Server();
// basics
int Accept(SOCKET_T);
int Write(const void*, int);
int Read(void*, int);
// options
void SetCA(const char*);
void SetCert(const char*);
void SetKey(const char*);
private:
struct ServerImpl;
ServerImpl* pimpl_;
Server(const Server&); // hide copy
Server& operator=(const Server&); // and assign
};
} // namespace yaSSL
#endif // yaSSL_EXT_HPP

View File

@ -59,6 +59,10 @@ enum YasslError {
enum Library { yaSSL_Lib = 0, CryptoLib, SocketLib };
enum { MAX_ERROR_SZ = 80 };
void SetErrorString(YasslError, char*);
// Base class for all yaSSL exceptions
class Error : public mySTL::runtime_error {

View File

@ -662,7 +662,7 @@ struct Parameters {
uint8 suites_size_;
Cipher suites_[MAX_SUITE_SZ];
char cipher_name_[MAX_SUITE_NAME];
char cipher_list_[MAX_CIPHER_LIST];
char cipher_list_[MAX_CIPHERS][MAX_SUITE_NAME];
Parameters(ConnectionEnd, const Ciphers&, ProtocolVersion);

View File

@ -77,8 +77,6 @@ enum ServerState {
// combines all states
class States {
enum {MAX_ERROR_SZ = 80 };
RecordLayerState recordLayer_;
HandShakeState handshakeLayer_;
ClientState clientState_;
@ -227,7 +225,8 @@ sslFactory& GetSSL_Factory();
class SSL_METHOD {
ProtocolVersion version_;
ConnectionEnd side_;
bool verifyPeer_;
bool verifyPeer_; // request or send certificate
bool verifyNone_; // whether to verify certificate
bool failNoCert_;
public:
explicit SSL_METHOD(ConnectionEnd ce, ProtocolVersion pv);
@ -236,9 +235,11 @@ public:
ConnectionEnd getSide() const;
void setVerifyPeer();
void setVerifyNone();
void setFailNoCert();
bool verifyPeer() const;
bool verifyNone() const;
bool failNoCert() const;
private:
SSL_METHOD(const SSL_METHOD&); // hide copy
@ -331,6 +332,7 @@ public:
const Stats& GetStats() const;
void setVerifyPeer();
void setVerifyNone();
void setFailNoCert();
bool SetCipherList(const char*);
bool SetDH(const DH&);

View File

@ -39,6 +39,8 @@ namespace yaSSL {
void CleanUp();
#ifdef YASSL_PURE_C
// library allocation
struct new_t {}; // yaSSL New type
extern new_t ys; // pass in parameter
@ -74,6 +76,7 @@ void ysArrayDelete(T* ptr)
::operator delete[](ptr, yaSSL::ys);
}
#define NEW_YS new (ys)
// to resolve compiler generated operator delete on base classes with
// virtual destructors (when on stack), make sure doesn't get called
@ -83,6 +86,30 @@ public:
};
#else // YASSL_PURE_C
template<typename T>
void ysDelete(T* ptr)
{
delete ptr;
}
template<typename T>
void ysArrayDelete(T* ptr)
{
delete[] ptr;
}
#define NEW_YS new
class virtual_base {};
#endif // YASSL_PURE_C
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
@ -110,7 +137,7 @@ const int KEY_PREFIX = 7; // up to 7 prefix letters for key rounds
const int FORTEZZA_MAX = 128; // Maximum Fortezza Key length
const int MAX_SUITE_SZ = 64; // 32 max suites * sizeof(suite)
const int MAX_SUITE_NAME = 48; // max length of suite name
const int MAX_CIPHER_LIST = 512; // max length of cipher list names
const int MAX_CIPHERS = 32; // max supported ciphers for cipher list
const int SIZEOF_ENUM = 1; // SSL considers an enum 1 byte, not 4
const int SIZEOF_SENDER = 4; // Sender constant, for finished generation
const int PAD_MD5 = 48; // pad length 1 and 2 for md5 finished

View File

@ -28,6 +28,9 @@
#define mySTL_HELPERS_HPP
#include <stdlib.h>
#ifdef _MSC_VER
#include <new>
#endif
/*
Workaround for the lack of operator new(size_t, void*)
@ -43,7 +46,6 @@
typedef Dummy* yassl_pointer;
namespace mySTL {

View File

@ -24,6 +24,7 @@
* with SSL types and sockets
*/
#include <string.h> // memcpy
#include "runtime.hpp"
#include "buffer.hpp"
@ -63,13 +64,13 @@ input_buffer::input_buffer()
input_buffer::input_buffer(uint s)
: size_(0), current_(0), buffer_(new (ys) byte[s]), end_(buffer_ + s)
: size_(0), current_(0), buffer_(NEW_YS byte[s]), end_(buffer_ + s)
{}
// with assign
input_buffer::input_buffer(uint s, const byte* t, uint len)
: size_(0), current_(0), buffer_(new (ys) byte[s]), end_(buffer_ + s)
: size_(0), current_(0), buffer_(NEW_YS byte[s]), end_(buffer_ + s)
{
assign(t, len);
}
@ -85,7 +86,7 @@ input_buffer::~input_buffer()
void input_buffer::allocate(uint s)
{
assert(!buffer_); // find realloc error
buffer_ = new (ys) byte[s];
buffer_ = NEW_YS byte[s];
end_ = buffer_ + s;
}
@ -97,7 +98,7 @@ byte* input_buffer::get_buffer() const
}
// after a raw write user can set new (ys) size
// after a raw write user can set NEW_YS size
// if you know the size before the write use assign()
void input_buffer::add_size(uint i)
{
@ -199,13 +200,13 @@ output_buffer::output_buffer()
// with allocate
output_buffer::output_buffer(uint s)
: current_(0), buffer_(new (ys) byte[s]), end_(buffer_ + s)
: current_(0), buffer_(NEW_YS byte[s]), end_(buffer_ + s)
{}
// with assign
output_buffer::output_buffer(uint s, const byte* t, uint len)
: current_(0), buffer_(new (ys) byte[s]), end_(buffer_+ s)
: current_(0), buffer_(NEW_YS byte[s]), end_(buffer_+ s)
{
write(t, len);
}
@ -240,7 +241,7 @@ void output_buffer::set_current(uint c)
void output_buffer::allocate(uint s)
{
assert(!buffer_); // find realloc error
buffer_ = new (ys) byte[s]; end_ = buffer_ + s;
buffer_ = NEW_YS byte[s]; end_ = buffer_ + s;
}

View File

@ -39,7 +39,7 @@
namespace yaSSL {
x509::x509(uint sz) : length_(sz), buffer_(new (ys) opaque[sz])
x509::x509(uint sz) : length_(sz), buffer_(NEW_YS opaque[sz])
{
}
@ -51,7 +51,7 @@ x509::~x509()
x509::x509(const x509& that) : length_(that.length_),
buffer_(new (ys) opaque[length_])
buffer_(NEW_YS opaque[length_])
{
memcpy(buffer_, that.buffer_, length_);
}
@ -92,7 +92,8 @@ opaque* x509::use_buffer()
//CertManager
CertManager::CertManager()
: peerX509_(0), verifyPeer_(false), failNoCert_(false), sendVerify_(false)
: peerX509_(0), verifyPeer_(false), verifyNone_(false), failNoCert_(false),
sendVerify_(false)
{}
@ -114,6 +115,12 @@ bool CertManager::verifyPeer() const
}
bool CertManager::verifyNone() const
{
return verifyNone_;
}
bool CertManager::failNoCert() const
{
return failNoCert_;
@ -132,6 +139,12 @@ void CertManager::setVerifyPeer()
}
void CertManager::setVerifyNone()
{
verifyNone_ = true;
}
void CertManager::setFailNoCert()
{
failNoCert_ = true;
@ -153,7 +166,7 @@ void CertManager::AddPeerCert(x509* x)
void CertManager::CopySelfCert(const x509* x)
{
if (x)
list_.push_back(new (ys) x509(*x));
list_.push_back(NEW_YS x509(*x));
}
@ -161,11 +174,12 @@ void CertManager::CopySelfCert(const x509* x)
int CertManager::CopyCaCert(const x509* x)
{
TaoCrypt::Source source(x->get_buffer(), x->get_length());
TaoCrypt::CertDecoder cert(source, true, &signers_);
TaoCrypt::CertDecoder cert(source, true, &signers_, verifyNone_,
TaoCrypt::CertDecoder::CA);
if (!cert.GetError().What()) {
const TaoCrypt::PublicKey& key = cert.GetPublicKey();
signers_.push_back(new (ys) TaoCrypt::Signer(key.GetKey(), key.size(),
signers_.push_back(NEW_YS TaoCrypt::Signer(key.GetKey(), key.size(),
cert.GetCommonName(), cert.GetHash()));
}
return cert.GetError().What();
@ -228,13 +242,13 @@ int CertManager::Validate()
while ( count > 1 ) {
TaoCrypt::Source source((*last)->get_buffer(), (*last)->get_length());
TaoCrypt::CertDecoder cert(source, true, &signers_);
TaoCrypt::CertDecoder cert(source, true, &signers_, verifyNone_);
if (int err = cert.GetError().What())
return err;
const TaoCrypt::PublicKey& key = cert.GetPublicKey();
signers_.push_back(new (ys) TaoCrypt::Signer(key.GetKey(), key.size(),
signers_.push_back(NEW_YS TaoCrypt::Signer(key.GetKey(), key.size(),
cert.GetCommonName(), cert.GetHash()));
--last;
--count;
@ -243,7 +257,7 @@ int CertManager::Validate()
if (count) {
// peer's is at the front
TaoCrypt::Source source((*last)->get_buffer(), (*last)->get_length());
TaoCrypt::CertDecoder cert(source, true, &signers_);
TaoCrypt::CertDecoder cert(source, true, &signers_, verifyNone_);
if (int err = cert.GetError().What())
return err;
@ -259,7 +273,7 @@ int CertManager::Validate()
int iSz = cert.GetIssuer() ? strlen(cert.GetIssuer()) + 1 : 0;
int sSz = cert.GetCommonName() ? strlen(cert.GetCommonName()) + 1 : 0;
peerX509_ = new (ys) X509(cert.GetIssuer(), iSz, cert.GetCommonName(),
peerX509_ = NEW_YS X509(cert.GetIssuer(), iSz, cert.GetCommonName(),
sSz);
}
return 0;

View File

@ -58,13 +58,13 @@ struct MD5::MD5Impl {
};
MD5::MD5() : pimpl_(new (ys) MD5Impl) {}
MD5::MD5() : pimpl_(NEW_YS MD5Impl) {}
MD5::~MD5() { ysDelete(pimpl_); }
MD5::MD5(const MD5& that) : Digest(), pimpl_(new (ys)
MD5::MD5(const MD5& that) : Digest(), pimpl_(NEW_YS
MD5Impl(that.pimpl_->md5_)) {}
@ -116,13 +116,13 @@ struct SHA::SHAImpl {
};
SHA::SHA() : pimpl_(new (ys) SHAImpl) {}
SHA::SHA() : pimpl_(NEW_YS SHAImpl) {}
SHA::~SHA() { ysDelete(pimpl_); }
SHA::SHA(const SHA& that) : Digest(), pimpl_(new (ys) SHAImpl(that.pimpl_->sha_)) {}
SHA::SHA(const SHA& that) : Digest(), pimpl_(NEW_YS SHAImpl(that.pimpl_->sha_)) {}
SHA& SHA::operator=(const SHA& that)
{
@ -173,13 +173,13 @@ struct RMD::RMDImpl {
};
RMD::RMD() : pimpl_(new (ys) RMDImpl) {}
RMD::RMD() : pimpl_(NEW_YS RMDImpl) {}
RMD::~RMD() { ysDelete(pimpl_); }
RMD::RMD(const RMD& that) : Digest(), pimpl_(new (ys) RMDImpl(that.pimpl_->rmd_)) {}
RMD::RMD(const RMD& that) : Digest(), pimpl_(NEW_YS RMDImpl(that.pimpl_->rmd_)) {}
RMD& RMD::operator=(const RMD& that)
{
@ -230,7 +230,7 @@ struct HMAC_MD5::HMAC_MD5Impl {
HMAC_MD5::HMAC_MD5(const byte* secret, unsigned int len)
: pimpl_(new (ys) HMAC_MD5Impl)
: pimpl_(NEW_YS HMAC_MD5Impl)
{
pimpl_->mac_.SetKey(secret, len);
}
@ -280,7 +280,7 @@ struct HMAC_SHA::HMAC_SHAImpl {
HMAC_SHA::HMAC_SHA(const byte* secret, unsigned int len)
: pimpl_(new (ys) HMAC_SHAImpl)
: pimpl_(NEW_YS HMAC_SHAImpl)
{
pimpl_->mac_.SetKey(secret, len);
}
@ -331,7 +331,7 @@ struct HMAC_RMD::HMAC_RMDImpl {
HMAC_RMD::HMAC_RMD(const byte* secret, unsigned int len)
: pimpl_(new (ys) HMAC_RMDImpl)
: pimpl_(NEW_YS HMAC_RMDImpl)
{
pimpl_->mac_.SetKey(secret, len);
}
@ -379,7 +379,7 @@ struct DES::DESImpl {
};
DES::DES() : pimpl_(new (ys) DESImpl) {}
DES::DES() : pimpl_(NEW_YS DESImpl) {}
DES::~DES() { ysDelete(pimpl_); }
@ -415,7 +415,7 @@ struct DES_EDE::DES_EDEImpl {
};
DES_EDE::DES_EDE() : pimpl_(new (ys) DES_EDEImpl) {}
DES_EDE::DES_EDE() : pimpl_(NEW_YS DES_EDEImpl) {}
DES_EDE::~DES_EDE() { ysDelete(pimpl_); }
@ -453,7 +453,7 @@ struct RC4::RC4Impl {
};
RC4::RC4() : pimpl_(new (ys) RC4Impl) {}
RC4::RC4() : pimpl_(NEW_YS RC4Impl) {}
RC4::~RC4() { ysDelete(pimpl_); }
@ -495,7 +495,7 @@ struct AES::AESImpl {
};
AES::AES(unsigned int ks) : pimpl_(new (ys) AESImpl(ks)) {}
AES::AES(unsigned int ks) : pimpl_(NEW_YS AESImpl(ks)) {}
AES::~AES() { ysDelete(pimpl_); }
@ -536,7 +536,7 @@ struct RandomPool::RandomImpl {
TaoCrypt::RandomNumberGenerator RNG_;
};
RandomPool::RandomPool() : pimpl_(new (ys) RandomImpl) {}
RandomPool::RandomPool() : pimpl_(NEW_YS RandomImpl) {}
RandomPool::~RandomPool() { ysDelete(pimpl_); }
@ -580,7 +580,7 @@ void DSS::DSSImpl::SetPrivate(const byte* key, unsigned int sz)
// Set public or private key
DSS::DSS(const byte* key, unsigned int sz, bool publicKey)
: pimpl_(new (ys) DSSImpl)
: pimpl_(NEW_YS DSSImpl)
{
if (publicKey)
pimpl_->SetPublic(key, sz);
@ -651,7 +651,7 @@ void RSA::RSAImpl::SetPrivate(const byte* key, unsigned int sz)
// Set public or private key
RSA::RSA(const byte* key, unsigned int sz, bool publicKey)
: pimpl_(new (ys) RSAImpl)
: pimpl_(NEW_YS RSAImpl)
{
if (publicKey)
pimpl_->SetPublic(key, sz);
@ -723,13 +723,13 @@ struct Integer::IntegerImpl {
explicit IntegerImpl(const TaoCrypt::Integer& i) : int_(i) {}
};
Integer::Integer() : pimpl_(new (ys) IntegerImpl) {}
Integer::Integer() : pimpl_(NEW_YS IntegerImpl) {}
Integer::~Integer() { ysDelete(pimpl_); }
Integer::Integer(const Integer& other) : pimpl_(new (ys)
Integer::Integer(const Integer& other) : pimpl_(NEW_YS
IntegerImpl(other.pimpl_->int_))
{}
@ -773,9 +773,9 @@ struct DiffieHellman::DHImpl {
void AllocKeys(unsigned int pubSz, unsigned int privSz, unsigned int agrSz)
{
publicKey_ = new (ys) byte[pubSz];
privateKey_ = new (ys) byte[privSz];
agreedKey_ = new (ys) byte[agrSz];
publicKey_ = NEW_YS byte[pubSz];
privateKey_ = NEW_YS byte[privSz];
agreedKey_ = NEW_YS byte[agrSz];
}
};
@ -784,7 +784,7 @@ struct DiffieHellman::DHImpl {
/*
// server Side DH, server's view
DiffieHellman::DiffieHellman(const char* file, const RandomPool& random)
: pimpl_(new (ys) DHImpl(random.pimpl_->RNG_))
: pimpl_(NEW_YS DHImpl(random.pimpl_->RNG_))
{
using namespace TaoCrypt;
Source source;
@ -808,12 +808,12 @@ DiffieHellman::DiffieHellman(const char* file, const RandomPool& random)
DiffieHellman::DiffieHellman(const byte* p, unsigned int pSz, const byte* g,
unsigned int gSz, const byte* pub,
unsigned int pubSz, const RandomPool& random)
: pimpl_(new (ys) DHImpl(random.pimpl_->RNG_))
: pimpl_(NEW_YS DHImpl(random.pimpl_->RNG_))
{
using TaoCrypt::Integer;
pimpl_->dh_.Initialize(Integer(p, pSz).Ref(), Integer(g, gSz).Ref());
pimpl_->publicKey_ = new (ys) opaque[pubSz];
pimpl_->publicKey_ = NEW_YS opaque[pubSz];
memcpy(pimpl_->publicKey_, pub, pubSz);
}
@ -821,7 +821,7 @@ DiffieHellman::DiffieHellman(const byte* p, unsigned int pSz, const byte* g,
// Server Side DH, server's view
DiffieHellman::DiffieHellman(const Integer& p, const Integer& g,
const RandomPool& random)
: pimpl_(new (ys) DHImpl(random.pimpl_->RNG_))
: pimpl_(NEW_YS DHImpl(random.pimpl_->RNG_))
{
using TaoCrypt::Integer;
@ -839,7 +839,7 @@ DiffieHellman::~DiffieHellman() { ysDelete(pimpl_); }
// Client side and view, use server that for p and g
DiffieHellman::DiffieHellman(const DiffieHellman& that)
: pimpl_(new (ys) DHImpl(*that.pimpl_))
: pimpl_(NEW_YS DHImpl(*that.pimpl_))
{
pimpl_->dh_.GenerateKeyPair(pimpl_->ranPool_, pimpl_->privateKey_,
pimpl_->publicKey_);
@ -855,9 +855,9 @@ DiffieHellman& DiffieHellman::operator=(const DiffieHellman& that)
}
void DiffieHellman::makeAgreement(const byte* other)
void DiffieHellman::makeAgreement(const byte* other, unsigned int otherSz)
{
pimpl_->dh_.Agree(pimpl_->agreedKey_, pimpl_->privateKey_, other);
pimpl_->dh_.Agree(pimpl_->agreedKey_, pimpl_->privateKey_, other, otherSz);
}
@ -960,7 +960,7 @@ x509* PemToDer(const char* fname, CertType type)
Base64Decoder b64Dec(der);
uint sz = der.size();
mySTL::auto_ptr<x509> x(new (ys) x509(sz), ysDelete);
mySTL::auto_ptr<x509> x(NEW_YS x509(sz), ysDelete);
memcpy(x->use_buffer(), der.get_buffer(), sz);
fclose(file);

View File

@ -24,6 +24,8 @@
* the various handshake messages.
*/
#include "runtime.hpp"
#include "handshake.hpp"
#include "yassl_int.hpp"
@ -362,9 +364,9 @@ void p_hash(output_buffer& result, const output_buffer& secret,
if (lastLen) times += 1;
if (hash == md5)
hmac.reset(new (ys) HMAC_MD5(secret.get_buffer(), secret.get_size()));
hmac.reset(NEW_YS HMAC_MD5(secret.get_buffer(), secret.get_size()));
else
hmac.reset(new (ys) HMAC_SHA(secret.get_buffer(), secret.get_size()));
hmac.reset(NEW_YS HMAC_SHA(secret.get_buffer(), secret.get_size()));
// A0 = seed
hmac->get_digest(previous, seed.get_buffer(), seed.get_size());// A1
uint lastTime = times - 1;
@ -582,11 +584,11 @@ void TLS_hmac(SSL& ssl, byte* digest, const byte* buffer, uint sz,
MACAlgorithm algo = ssl.getSecurity().get_parms().mac_algorithm_;
if (algo == sha)
hmac.reset(new (ys) HMAC_SHA(ssl.get_macSecret(verify), SHA_LEN));
hmac.reset(NEW_YS HMAC_SHA(ssl.get_macSecret(verify), SHA_LEN));
else if (algo == rmd)
hmac.reset(new (ys) HMAC_RMD(ssl.get_macSecret(verify), RMD_LEN));
hmac.reset(NEW_YS HMAC_RMD(ssl.get_macSecret(verify), RMD_LEN));
else
hmac.reset(new (ys) HMAC_MD5(ssl.get_macSecret(verify), MD5_LEN));
hmac.reset(NEW_YS HMAC_MD5(ssl.get_macSecret(verify), MD5_LEN));
hmac->update(seq, SEQ_SZ); // seq_num
inner[0] = content; // type
@ -603,7 +605,7 @@ void TLS_hmac(SSL& ssl, byte* digest, const byte* buffer, uint sz,
void PRF(byte* digest, uint digLen, const byte* secret, uint secLen,
const byte* label, uint labLen, const byte* seed, uint seedLen)
{
uint half = secLen / 2 + secLen % 2;
uint half = (secLen + 1) / 2;
output_buffer md5_half(half);
output_buffer sha_half(half);
@ -648,18 +650,19 @@ void build_certHashes(SSL& ssl, Hashes& hashes)
}
// do process input requests
mySTL::auto_ptr<input_buffer>
DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered)
{
ssl.getSocket().wait(); // wait for input if blocking
uint ready = ssl.getSocket().get_ready();
if (!ready) {
// Nothing to receive after blocking wait => error
// wait for input if blocking
if (!ssl.getSocket().wait()) {
ssl.SetError(receive_error);
buffered.reset(0);
return buffered;
}
uint ready = ssl.getSocket().get_ready();
if (!ready) return buffered;
// add buffered data if its there
uint buffSz = buffered.get() ? buffered.get()->get_size() : 0;
@ -690,7 +693,7 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr<input_buffer> buffered)
// make sure we have enough input in buffer to process this record
if (hdr.length_ > buffer.get_remaining()) {
uint sz = buffer.get_remaining() + RECORD_HEADER;
buffered.reset(new (ys) input_buffer(sz, buffer.get_buffer() +
buffered.reset(NEW_YS input_buffer(sz, buffer.get_buffer() +
buffer.get_current() - RECORD_HEADER, sz));
break;
}
@ -730,6 +733,7 @@ void processReply(SSL& ssl)
buffered = tmp;
else
break;
if (ssl.GetError()) return;
}
}
@ -767,7 +771,7 @@ void sendClientKeyExchange(SSL& ssl, BufferOutput buffer)
RecordLayerHeader rlHeader;
HandShakeHeader hsHeader;
mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer, ysDelete);
mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer, ysDelete);
buildHeaders(ssl, hsHeader, rlHeader, ck);
buildOutput(*out.get(), rlHeader, hsHeader, ck);
hashHandShake(ssl, *out.get());
@ -788,7 +792,7 @@ void sendServerKeyExchange(SSL& ssl, BufferOutput buffer)
RecordLayerHeader rlHeader;
HandShakeHeader hsHeader;
mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer, ysDelete);
mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer, ysDelete);
buildHeaders(ssl, hsHeader, rlHeader, sk);
buildOutput(*out.get(), rlHeader, hsHeader, sk);
hashHandShake(ssl, *out.get());
@ -813,7 +817,7 @@ void sendChangeCipher(SSL& ssl, BufferOutput buffer)
ChangeCipherSpec ccs;
RecordLayerHeader rlHeader;
buildHeader(ssl, rlHeader, ccs);
mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer, ysDelete);
mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer, ysDelete);
buildOutput(*out.get(), rlHeader, ccs);
if (buffer == buffered)
@ -830,7 +834,7 @@ void sendFinished(SSL& ssl, ConnectionEnd side, BufferOutput buffer)
Finished fin;
buildFinished(ssl, fin, side == client_end ? client : server);
mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer, ysDelete);
mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer, ysDelete);
cipherFinished(ssl, fin, *out.get()); // hashes handshake
if (ssl.getSecurity().get_resuming()) {
@ -914,7 +918,7 @@ void sendServerHello(SSL& ssl, BufferOutput buffer)
ServerHello sh(ssl.getSecurity().get_connection().version_);
RecordLayerHeader rlHeader;
HandShakeHeader hsHeader;
mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer, ysDelete);
mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer, ysDelete);
buildServerHello(ssl, sh);
ssl.set_random(sh.get_random(), server_end);
@ -937,7 +941,7 @@ void sendServerHelloDone(SSL& ssl, BufferOutput buffer)
ServerHelloDone shd;
RecordLayerHeader rlHeader;
HandShakeHeader hsHeader;
mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer, ysDelete);
mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer, ysDelete);
buildHeaders(ssl, hsHeader, rlHeader, shd);
buildOutput(*out.get(), rlHeader, hsHeader, shd);
@ -958,7 +962,7 @@ void sendCertificate(SSL& ssl, BufferOutput buffer)
Certificate cert(ssl.getCrypto().get_certManager().get_cert());
RecordLayerHeader rlHeader;
HandShakeHeader hsHeader;
mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer, ysDelete);
mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer, ysDelete);
buildHeaders(ssl, hsHeader, rlHeader, cert);
buildOutput(*out.get(), rlHeader, hsHeader, cert);
@ -980,7 +984,7 @@ void sendCertificateRequest(SSL& ssl, BufferOutput buffer)
request.Build();
RecordLayerHeader rlHeader;
HandShakeHeader hsHeader;
mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer, ysDelete);
mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer, ysDelete);
buildHeaders(ssl, hsHeader, rlHeader, request);
buildOutput(*out.get(), rlHeader, hsHeader, request);
@ -1002,7 +1006,7 @@ void sendCertificateVerify(SSL& ssl, BufferOutput buffer)
verify.Build(ssl);
RecordLayerHeader rlHeader;
HandShakeHeader hsHeader;
mySTL::auto_ptr<output_buffer> out(new (ys) output_buffer, ysDelete);
mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer, ysDelete);
buildHeaders(ssl, hsHeader, rlHeader, verify);
buildOutput(*out.get(), rlHeader, hsHeader, verify);

27
extra/yassl/src/make.bat Normal file
View File

@ -0,0 +1,27 @@
# quick and dirty build file for testing different MSDEVs
setlocal
set myFLAGS= /I../include /I../mySTL /I../taocrypt/include /W3 /c /ZI
cl %myFLAGS% buffer.cpp
cl %myFLAGS% cert_wrapper.cpp
cl %myFLAGS% crypto_wrapper.cpp
cl %myFLAGS% handshake.cpp
cl %myFLAGS% lock.cpp
cl %myFLAGS% log.cpp
cl %myFLAGS% socket_wrapper.cpp
cl %myFLAGS% ssl.cpp
cl %myFLAGS% template_instnt.cpp
cl %myFLAGS% timer.cpp
cl %myFLAGS% yassl.cpp
cl %myFLAGS% yassl_error.cpp
cl %myFLAGS% yassl_imp.cpp
cl %myFLAGS% yassl_int.cpp
link.exe -lib /out:yassl.lib buffer.obj cert_wrapper.obj crypto_wrapper.obj handshake.obj lock.obj log.obj socket_wrapper.obj ssl.obj template_instnt.obj timer.obj yassl.obj yassl_error.obj yassl_imp.obj yassl_int.obj

View File

@ -46,9 +46,11 @@
#ifdef _WIN32
const int SOCKET_EINVAL = WSAEINVAL;
const int SOCKET_EWOULDBLOCK = WSAEWOULDBLOCK;
const int SOCKET_EAGAIN = WSAEWOULDBLOCK;
#else
const int SOCKET_EINVAL = EINVAL;
const int SOCKET_EWOULDBLOCK = EWOULDBLOCK;
const int SOCKET_EAGAIN = EAGAIN;
#endif // _WIN32
@ -101,7 +103,7 @@ uint Socket::get_ready() const
64-bit Solaris requires the variable passed to
FIONREAD be a 32-bit value.
*/
int ready = 0;
unsigned int ready = 0;
ioctl(socket_, FIONREAD, &ready);
#endif
@ -126,18 +128,24 @@ uint Socket::receive(byte* buf, unsigned int sz, int flags) const
assert(socket_ != INVALID_SOCKET);
int recvd = ::recv(socket_, reinterpret_cast<char *>(buf), sz, flags);
if (recvd == -1)
// idea to seperate error from would block by arnetheduck@gmail.com
if (recvd == -1) {
if (get_lastError() == SOCKET_EWOULDBLOCK ||
get_lastError() == SOCKET_EAGAIN)
return 0;
}
else if (recvd == 0)
return static_cast<uint>(-1);
return recvd;
}
// wait if blocking for input, or error
void Socket::wait() const
// wait if blocking for input, return false for error
bool Socket::wait() const
{
byte b;
receive(&b, 1, MSG_PEEK);
return receive(&b, 1, MSG_PEEK) != static_cast<uint>(-1);
}

View File

@ -38,6 +38,14 @@
#include "yassl_int.hpp"
#include <stdio.h>
#ifdef _WIN32
#include <windows.h> // FindFirstFile etc..
#else
#include <sys/types.h> // file helper
#include <sys/stat.h> // stat
#include <dirent.h> // opendir
#endif
namespace yaSSL {
@ -52,25 +60,25 @@ SSL_METHOD* SSLv3_method()
SSL_METHOD* SSLv3_server_method()
{
return new (ys) SSL_METHOD(server_end, ProtocolVersion(3,0));
return NEW_YS SSL_METHOD(server_end, ProtocolVersion(3,0));
}
SSL_METHOD* SSLv3_client_method()
{
return new (ys) SSL_METHOD(client_end, ProtocolVersion(3,0));
return NEW_YS SSL_METHOD(client_end, ProtocolVersion(3,0));
}
SSL_METHOD* TLSv1_server_method()
{
return new (ys) SSL_METHOD(server_end, ProtocolVersion(3,1));
return NEW_YS SSL_METHOD(server_end, ProtocolVersion(3,1));
}
SSL_METHOD* TLSv1_client_method()
{
return new (ys) SSL_METHOD(client_end, ProtocolVersion(3,1));
return NEW_YS SSL_METHOD(client_end, ProtocolVersion(3,1));
}
@ -83,7 +91,7 @@ SSL_METHOD* SSLv23_server_method()
SSL_CTX* SSL_CTX_new(SSL_METHOD* method)
{
return new (ys) SSL_CTX(method);
return NEW_YS SSL_CTX(method);
}
@ -95,7 +103,7 @@ void SSL_CTX_free(SSL_CTX* ctx)
SSL* SSL_new(SSL_CTX* ctx)
{
return new (ys) SSL(ctx);
return NEW_YS SSL(ctx);
}
@ -115,7 +123,12 @@ int SSL_set_fd(SSL* ssl, int fd)
int SSL_connect(SSL* ssl)
{
sendClientHello(*ssl);
ClientState neededState = ssl->getSecurity().get_resuming() ?
serverFinishedComplete : serverHelloDoneComplete;
while (ssl->getStates().getClient() < neededState) {
if (ssl->GetError()) break;
processReply(*ssl);
}
if(ssl->getCrypto().get_certManager().sendVerify())
sendCertificate(*ssl);
@ -130,7 +143,10 @@ int SSL_connect(SSL* ssl)
sendFinished(*ssl, client_end);
ssl->flushBuffer();
if (!ssl->getSecurity().get_resuming())
while (ssl->getStates().getClient() < serverFinishedComplete) {
if (ssl->GetError()) break;
processReply(*ssl);
}
ssl->verifyState(serverFinishedComplete);
ssl->useLog().ShowTCP(ssl->getSocket().get_fd());
@ -171,9 +187,7 @@ int SSL_accept(SSL* ssl)
sendServerHelloDone(*ssl);
ssl->flushBuffer();
// Java Client sends fragmented response
while (ssl->getStates().getServer() <
clientFinishedComplete) {
while (ssl->getStates().getServer() < clientFinishedComplete) {
if (ssl->GetError()) break;
processReply(*ssl);
}
@ -182,10 +196,7 @@ int SSL_accept(SSL* ssl)
sendFinished(*ssl, server_end);
ssl->flushBuffer();
if (ssl->getSecurity().get_resuming()) {
// Java Client sends fragmented response
while (ssl->getStates().getServer() <
clientFinishedComplete) {
while (ssl->getStates().getServer() < clientFinishedComplete) {
if (ssl->GetError()) break;
processReply(*ssl);
}
@ -281,9 +292,15 @@ char* SSL_get_shared_ciphers(SSL* /*ssl*/, char* buf, int len)
}
const char* SSL_get_cipher_list(SSL* ssl, int /*priority */)
const char* SSL_get_cipher_list(SSL* ssl, int priority)
{
return ssl->getSecurity().get_parms().cipher_list_;
if (priority < 0 || priority >= MAX_CIPHERS)
return 0;
if (ssl->getSecurity().get_parms().cipher_list_[priority][0])
return ssl->getSecurity().get_parms().cipher_list_[priority];
return 0;
}
@ -455,7 +472,7 @@ int read_file(SSL_CTX* ctx, const char* file, int format, CertType type)
fseek(input, 0, SEEK_END);
long sz = ftell(input);
rewind(input);
x = new (ys) x509(sz); // takes ownership
x = NEW_YS x509(sz); // takes ownership
size_t bytes = fread(x->use_buffer(), sz, 1, input);
if (bytes != 1) {
fclose(input);
@ -492,16 +509,74 @@ void SSL_CTX_set_verify(SSL_CTX* ctx, int mode, VerifyCallback /*vc*/)
if (mode & SSL_VERIFY_PEER)
ctx->setVerifyPeer();
if (mode == SSL_VERIFY_NONE)
ctx->setVerifyNone();
if (mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)
ctx->setFailNoCert();
}
int SSL_CTX_load_verify_locations(SSL_CTX* ctx, const char* file,
const char* /*path*/)
const char* path)
{
// just files for now
return read_file(ctx, file, SSL_FILETYPE_PEM, CA);
int ret = SSL_SUCCESS;
const int HALF_PATH = 128;
if (file) ret = read_file(ctx, file, SSL_FILETYPE_PEM, CA);
if (ret == SSL_SUCCESS && path) {
// call read_file for each reqular file in path
#ifdef _WIN32
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
char name[MAX_PATH + 1]; // directory specification
strncpy(name, path, MAX_PATH - 3);
strncat(name, "\\*", 3);
hFind = FindFirstFile(name, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE) return SSL_BAD_PATH;
do {
if (FindFileData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY) {
strncpy(name, path, MAX_PATH - 2 - HALF_PATH);
strncat(name, "\\", 2);
strncat(name, FindFileData.cFileName, HALF_PATH);
ret = read_file(ctx, name, SSL_FILETYPE_PEM, CA);
}
} while (ret == SSL_SUCCESS && FindNextFile(hFind, &FindFileData));
FindClose(hFind);
#else // _WIN32
const int MAX_PATH = 260;
DIR* dir = opendir(path);
if (!dir) return SSL_BAD_PATH;
struct dirent* entry;
struct stat buf;
char name[MAX_PATH + 1];
while (ret == SSL_SUCCESS && (entry = readdir(dir))) {
strncpy(name, path, MAX_PATH - 1 - HALF_PATH);
strncat(name, "/", 1);
strncat(name, entry->d_name, HALF_PATH);
if (stat(name, &buf) < 0) return SSL_BAD_STAT;
if (S_ISREG(buf.st_mode))
ret = read_file(ctx, name, SSL_FILETYPE_PEM, CA);
}
closedir(dir);
#endif
}
return ret;
}
@ -648,13 +723,13 @@ void OpenSSL_add_all_algorithms() // compatibility only
{}
void SSL_library_init() // compatibility only
void SSL_library_init() // compatiblity only
{}
DH* DH_new(void)
{
DH* dh = new (ys) DH;
DH* dh = NEW_YS DH;
if (dh)
dh->p = dh->g = 0;
return dh;
@ -679,7 +754,7 @@ BIGNUM* BN_bin2bn(const unsigned char* num, int sz, BIGNUM* retVal)
if (!retVal) {
created = true;
bn.reset(new (ys) BIGNUM);
bn.reset(NEW_YS BIGNUM);
retVal = bn.get();
}
@ -706,12 +781,14 @@ void ERR_print_errors_fp(FILE* /*fp*/)
}
char* ERR_error_string(unsigned long /*err*/, char* buffer)
char* ERR_error_string(unsigned long errNumber, char* buffer)
{
// TODO:
static char* msg = "Not Implemented";
if (buffer)
return strncpy(buffer, msg, strlen(msg));
static char* msg = "Please supply a buffer for error string";
if (buffer) {
SetErrorString(YasslError(errNumber), buffer);
return buffer;
}
return msg;
}
@ -728,14 +805,14 @@ const char* X509_verify_cert_error_string(long /* error */)
const EVP_MD* EVP_md5(void)
{
// TODO: FIX add to some list for destruction
return new (ys) MD5;
return NEW_YS MD5;
}
const EVP_CIPHER* EVP_des_ede3_cbc(void)
{
// TODO: FIX add to some list for destruction
return new (ys) DES_EDE;
return NEW_YS DES_EDE;
}

View File

@ -35,13 +35,6 @@
#include "openssl/ssl.h"
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
#if !defined(USE_CRYPTOPP_LIB)
namespace TaoCrypt {
template class HMAC<MD5>;
template class HMAC<SHA>;
template class HMAC<RIPEMD160>;
}
#endif // USE_CRYPTOPP_LIB
namespace mySTL {
template class list<unsigned char*>;

View File

@ -26,17 +26,13 @@
#include "runtime.hpp"
#include "timer.hpp"
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#include <sys/time.h>
#endif
namespace yaSSL {
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
timer_d timer()
{
static bool init(false);
@ -61,6 +57,8 @@ namespace yaSSL {
#else // _WIN32
#include <sys/time.h>
timer_d timer()
{
struct timeval tv;

244
extra/yassl/src/yassl.cpp Normal file
View File

@ -0,0 +1,244 @@
/* yassl.cpp
*
* Copyright (C) 2003 Sawtooth Consulting Ltd.
*
* This file is part of yaSSL.
*
* yaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* yaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/* yaSSL implements external API
*/
#include "runtime.hpp"
#include "yassl.hpp"
#include "yassl_int.hpp"
#include "handshake.hpp"
#include <stdio.h>
#include "openssl/ssl.h" // get rid of this
// yaSSL overloads hide these
void* operator new[](size_t sz)
{
return ::operator new(sz);
}
void operator delete[](void* ptr)
{
::operator delete(ptr);
}
namespace yaSSL {
using mySTL::min;
struct Base {
SSL_METHOD* method_;
SSL_CTX* ctx_;
SSL* ssl_;
char* ca_;
char* cert_;
char* key_;
DH* dh_;
Base() : method_(0), ctx_(0), ssl_(0), ca_(0), cert_(0), key_(0), dh_(0)
{}
~Base()
{
if (dh_) DH_free(dh_);
delete[] key_;
delete[] cert_;
delete[] ca_;
SSL_CTX_free(ctx_); // frees method_ too
SSL_free(ssl_);
}
};
void SetDH(Base&);
void SetUpBase(Base& base, ConnectionEnd end, SOCKET_T s)
{
base.method_ = new SSL_METHOD(end, ProtocolVersion(3,1));
base.ctx_ = new SSL_CTX(base.method_);
if (base.ca_)
if (SSL_CTX_load_verify_locations(base.ctx_,
base.ca_, 0) != SSL_SUCCESS) assert(0);
if (base.cert_)
if (SSL_CTX_use_certificate_file(base.ctx_,
base.cert_, SSL_FILETYPE_PEM) != SSL_SUCCESS) assert(0);
if (base.key_)
if (SSL_CTX_use_PrivateKey_file(base.ctx_, base.key_,
SSL_FILETYPE_PEM) != SSL_SUCCESS) assert(0);
if (end == server_end) SetDH(base);
base.ssl_ = new SSL(base.ctx_);
base.ssl_->useSocket().set_fd(s);
}
void SetDH(Base& base)
{
static unsigned char dh512_p[] =
{
0xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89,0xD0,0xE4,0xAF,0x75,
0x6F,0x4C,0xCA,0x92,0xDD,0x4B,0xE5,0x33,0xB8,0x04,0xFB,0x0F,
0xED,0x94,0xEF,0x9C,0x8A,0x44,0x03,0xED,0x57,0x46,0x50,0xD3,
0x69,0x99,0xDB,0x29,0xD7,0x76,0x27,0x6B,0xA2,0xD3,0xD4,0x12,
0xE2,0x18,0xF4,0xDD,0x1E,0x08,0x4C,0xF6,0xD8,0x00,0x3E,0x7C,
0x47,0x74,0xE8,0x33,
};
static unsigned char dh512_g[] =
{
0x02,
};
if ( (base.dh_ = DH_new()) ) {
base.dh_->p = BN_bin2bn(dh512_p, sizeof(dh512_p), 0);
base.dh_->g = BN_bin2bn(dh512_g, sizeof(dh512_g), 0);
}
if (!base.dh_->p || !base.dh_->g) {
DH_free(base.dh_);
base.dh_ = 0;
}
SSL_CTX_set_tmp_dh(base.ctx_, base.dh_);
}
void NewCopy(char*& dst, const char* src)
{
size_t len = strlen(src) + 1;
dst = new char[len];
strncpy(dst, src, len);
}
// Client Implementation
struct Client::ClientImpl {
Base base_;
};
Client::Client() : pimpl_(new ClientImpl)
{}
Client::~Client() { delete pimpl_; }
int Client::Connect(SOCKET_T s)
{
SetUpBase(pimpl_->base_, client_end, s);
return SSL_connect(pimpl_->base_.ssl_);
}
int Client::Write(const void* buffer, int sz)
{
return sendData(*pimpl_->base_.ssl_, buffer, sz);
}
int Client::Read(void* buffer, int sz)
{
Data data(min(sz, MAX_RECORD_SIZE), static_cast<opaque*>(buffer));
return receiveData(*pimpl_->base_.ssl_, data);
}
void Client::SetCA(const char* name)
{
NewCopy(pimpl_->base_.ca_, name);
}
void Client::SetCert(const char* name)
{
NewCopy(pimpl_->base_.cert_, name);
}
void Client::SetKey(const char* name)
{
NewCopy(pimpl_->base_.key_, name);
}
// Server Implementation
struct Server::ServerImpl {
Base base_;
};
Server::Server() : pimpl_(new ServerImpl)
{}
Server::~Server() { delete pimpl_; }
int Server::Accept(SOCKET_T s)
{
SetUpBase(pimpl_->base_, server_end, s);
return SSL_accept(pimpl_->base_.ssl_);
}
int Server::Write(const void* buffer, int sz)
{
return sendData(*pimpl_->base_.ssl_, buffer, sz);
}
int Server::Read(void* buffer, int sz)
{
Data data(min(sz, MAX_RECORD_SIZE), static_cast<opaque*>(buffer));
return receiveData(*pimpl_->base_.ssl_, data);
}
void Server::SetCA(const char* name)
{
NewCopy(pimpl_->base_.ca_, name);
}
void Server::SetCert(const char* name)
{
NewCopy(pimpl_->base_.cert_, name);
}
void Server::SetKey(const char* name)
{
NewCopy(pimpl_->base_.key_, name);
}
} // namespace yaSSL

View File

@ -25,6 +25,7 @@
#include "runtime.hpp"
#include "yassl_error.hpp"
#include "error.hpp" // TaoCrypt error numbers
namespace yaSSL {
@ -48,6 +49,184 @@ Library Error::get_lib() const
}
void SetErrorString(YasslError error, char* buffer)
{
using namespace TaoCrypt;
const int max = MAX_ERROR_SZ; // shorthand
switch (error) {
// yaSSL proper errors
case range_error :
strncpy(buffer, "buffer index error, out of range", max);
break;
case realloc_error :
strncpy(buffer, "trying to realloc a fixed buffer", max);
break;
case factory_error :
strncpy(buffer, "unknown factory create request", max);
break;
case unknown_cipher :
strncpy(buffer, "trying to use an unknown cipher", max);
break;
case prefix_error :
strncpy(buffer, "bad master secret derivation, prefix too big", max);
break;
case record_layer :
strncpy(buffer, "record layer not ready yet", max);
break;
case handshake_layer :
strncpy(buffer, "handshake layer not ready yet", max);
break;
case out_of_order :
strncpy(buffer, "handshake message received in wrong order", max);
break;
case bad_input :
strncpy(buffer, "bad cipher suite input", max);
break;
case match_error :
strncpy(buffer, "unable to match a supported cipher suite", max);
break;
case no_key_file :
strncpy(buffer, "the server needs a private key file", max);
break;
case verify_error :
strncpy(buffer, "unable to verify peer checksum", max);
break;
case send_error :
strncpy(buffer, "socket layer send error", max);
break;
case receive_error :
strncpy(buffer, "socket layer receive error", max);
break;
case certificate_error :
strncpy(buffer, "unable to proccess cerificate", max);
break;
// TaoCrypt errors
case NO_ERROR :
strncpy(buffer, "not in error state", max);
break;
case WINCRYPT_E :
strncpy(buffer, "bad wincrypt acquire", max);
break;
case CRYPTGEN_E :
strncpy(buffer, "CryptGenRandom error", max);
break;
case OPEN_RAN_E :
strncpy(buffer, "unable to use random device", max);
break;
case READ_RAN_E :
strncpy(buffer, "unable to use random device", max);
break;
case INTEGER_E :
strncpy(buffer, "ASN: bad DER Integer Header", max);
break;
case SEQUENCE_E :
strncpy(buffer, "ASN: bad Sequence Header", max);
break;
case SET_E :
strncpy(buffer, "ASN: bad Set Header", max);
break;
case VERSION_E :
strncpy(buffer, "ASN: version length not 1", max);
break;
case SIG_OID_E :
strncpy(buffer, "ASN: signature OID mismatch", max);
break;
case BIT_STR_E :
strncpy(buffer, "ASN: bad BitString Header", max);
break;
case UNKNOWN_OID_E :
strncpy(buffer, "ASN: unknown key OID type", max);
break;
case OBJECT_ID_E :
strncpy(buffer, "ASN: bad Ojbect ID Header", max);
break;
case TAG_NULL_E :
strncpy(buffer, "ASN: expected TAG NULL", max);
break;
case EXPECT_0_E :
strncpy(buffer, "ASN: expected 0", max);
break;
case OCTET_STR_E :
strncpy(buffer, "ASN: bad Octet String Header", max);
break;
case TIME_E :
strncpy(buffer, "ASN: bad TIME", max);
break;
case DATE_SZ_E :
strncpy(buffer, "ASN: bad Date Size", max);
break;
case SIG_LEN_E :
strncpy(buffer, "ASN: bad Signature Length", max);
break;
case UNKOWN_SIG_E :
strncpy(buffer, "ASN: unknown signature OID", max);
break;
case UNKOWN_HASH_E :
strncpy(buffer, "ASN: unknown hash OID", max);
break;
case DSA_SZ_E :
strncpy(buffer, "ASN: bad DSA r or s size", max);
break;
case BEFORE_DATE_E :
strncpy(buffer, "ASN: before date in the future", max);
break;
case AFTER_DATE_E :
strncpy(buffer, "ASN: after date in the past", max);
break;
case SIG_CONFIRM_E :
strncpy(buffer, "ASN: bad self signature confirmation", max);
break;
case SIG_OTHER_E :
strncpy(buffer, "ASN: bad other signature confirmation", max);
break;
default :
strncpy(buffer, "unknown error number", max);
}
}
} // namespace yaSSL

View File

@ -29,6 +29,7 @@
#include "asn.hpp" // provide crypto wrapper??
namespace yaSSL {
@ -111,10 +112,14 @@ void ClientDiffieHellmanPublic::build(SSL& ssl)
uint keyLength = dhClient.get_agreedKeyLength(); // pub and agree same
alloc(keyLength, true);
dhClient.makeAgreement(dhServer.get_publicKey());
dhClient.makeAgreement(dhServer.get_publicKey(), keyLength);
c16toa(keyLength, Yc_);
memcpy(Yc_ + KEY_OFFSET, dhClient.get_publicKey(), keyLength);
// because of encoding first byte might be zero, don't use it for preMaster
if (*dhClient.get_agreedKey() == 0)
ssl.set_preMaster(dhClient.get_agreedKey() + 1, keyLength - 1);
else
ssl.set_preMaster(dhClient.get_agreedKey(), keyLength);
}
@ -134,10 +139,10 @@ void DH_Server::build(SSL& ssl)
const CertManager& cert = ssl.getCrypto().get_certManager();
if (ssl.getSecurity().get_parms().sig_algo_ == rsa_sa_algo)
auth.reset(new (ys) RSA(cert.get_privateKey(),
auth.reset(NEW_YS RSA(cert.get_privateKey(),
cert.get_privateKeyLength(), false));
else {
auth.reset(new (ys) DSS(cert.get_privateKey(),
auth.reset(NEW_YS DSS(cert.get_privateKey(),
cert.get_privateKeyLength(), false));
sigSz += DSS_ENCODED_EXTRA;
}
@ -168,7 +173,7 @@ void DH_Server::build(SSL& ssl)
byte hash[FINISHED_SZ];
MD5 md5;
SHA sha;
signature_ = new (ys) byte[sigSz];
signature_ = NEW_YS byte[sigSz];
const Connection& conn = ssl.getSecurity().get_connection();
// md5
@ -199,7 +204,7 @@ void DH_Server::build(SSL& ssl)
tmp.write(signature_, sigSz);
// key message
keyMessage_ = new (ys) opaque[length_];
keyMessage_ = NEW_YS opaque[length_];
memcpy(keyMessage_, tmp.get_buffer(), tmp.get_size());
}
@ -253,7 +258,7 @@ opaque* EncryptedPreMasterSecret::get_clientKey() const
void EncryptedPreMasterSecret::alloc(int sz)
{
length_ = sz;
secret_ = new (ys) opaque[sz];
secret_ = NEW_YS opaque[sz];
}
@ -269,10 +274,14 @@ void ClientDiffieHellmanPublic::read(SSL& ssl, input_buffer& input)
ato16(tmp, keyLength);
alloc(keyLength);
input.read(Yc_, length_);
dh.makeAgreement(Yc_);
input.read(Yc_, keyLength);
dh.makeAgreement(Yc_, keyLength);
ssl.set_preMaster(dh.get_agreedKey(), keyLength);
// because of encoding, first byte might be 0, don't use for preMaster
if (*dh.get_agreedKey() == 0)
ssl.set_preMaster(dh.get_agreedKey() + 1, dh.get_agreedKeyLength() - 1);
else
ssl.set_preMaster(dh.get_agreedKey(), dh.get_agreedKeyLength());
ssl.makeMasterSecret();
}
@ -303,7 +312,7 @@ opaque* ClientDiffieHellmanPublic::get_clientKey() const
void ClientDiffieHellmanPublic::alloc(int sz, bool offset)
{
length_ = sz + (offset ? KEY_OFFSET : 0);
Yc_ = new (ys) opaque[length_];
Yc_ = NEW_YS opaque[length_];
}
@ -348,7 +357,7 @@ void DH_Server::read(SSL& ssl, input_buffer& input)
tmp[1] = input[AUTO];
ato16(tmp, length);
signature_ = new (ys) byte[length];
signature_ = NEW_YS byte[length];
input.read(signature_, length);
// verify signature
@ -386,7 +395,7 @@ void DH_Server::read(SSL& ssl, input_buffer& input)
}
// save input
ssl.useCrypto().SetDH(new (ys) DiffieHellman(parms_.get_p(),
ssl.useCrypto().SetDH(NEW_YS DiffieHellman(parms_.get_p(),
parms_.get_pSize(), parms_.get_g(), parms_.get_gSize(),
parms_.get_pub(), parms_.get_pubSize(),
ssl.getCrypto().get_random()));
@ -438,7 +447,7 @@ void Parameters::SetSuites(ProtocolVersion pv)
int i = 0;
// available suites, best first
// when adding more, make sure cipher_names is updated and
// MAX_CIPHER_LIST is big enough
// MAX_CIPHERS is big enough
if (isTLS(pv)) {
suites_[i++] = 0x00;
@ -510,13 +519,10 @@ void Parameters::SetCipherNames()
for (int j = 0; j < suites; j++) {
int index = suites_[j*2 + 1]; // every other suite is suite id
int len = strlen(cipher_names[index]);
memcpy(&cipher_list_[pos], cipher_names[index], len);
pos += len;
cipher_list_[pos++] = ':';
int len = strlen(cipher_names[index]) + 1;
strncpy(cipher_list_[pos++], cipher_names[index], len);
}
if (suites)
cipher_list_[--pos] = 0;
cipher_list_[pos][0] = 0;
}
@ -928,7 +934,7 @@ void Data::Process(input_buffer& input, SSL& ssl)
// read data
if (dataSz) {
input_buffer* data;
ssl.addData(data = new (ys) input_buffer(dataSz));
ssl.addData(data = NEW_YS input_buffer(dataSz));
input.read(data->get_buffer(), dataSz);
data->add_size(dataSz);
@ -1025,7 +1031,7 @@ void Certificate::Process(input_buffer& input, SSL& ssl)
c24to32(tmp, cert_sz);
x509* myCert;
cm.AddPeerCert(myCert = new (ys) x509(cert_sz));
cm.AddPeerCert(myCert = NEW_YS x509(cert_sz));
input.read(myCert->use_buffer(), myCert->get_length());
list_sz -= cert_sz + CERT_HEADER;
@ -1111,21 +1117,21 @@ const opaque* ServerDHParams::get_pub() const
opaque* ServerDHParams::alloc_p(int sz)
{
p_ = new (ys) opaque[pSz_ = sz];
p_ = NEW_YS opaque[pSz_ = sz];
return p_;
}
opaque* ServerDHParams::alloc_g(int sz)
{
g_ = new (ys) opaque[gSz_ = sz];
g_ = NEW_YS opaque[gSz_ = sz];
return g_;
}
opaque* ServerDHParams::alloc_pub(int sz)
{
Ys_ = new (ys) opaque[pubSz_ = sz];
Ys_ = NEW_YS opaque[pubSz_ = sz];
return Ys_;
}
@ -1323,6 +1329,7 @@ input_buffer& operator>>(input_buffer& input, ClientHello& hello)
// Compression
hello.comp_len_ = input[AUTO];
while (hello.comp_len_--) // ignore for now
hello.compression_methods_ = CompressionMethod(input[AUTO]);
return input;
@ -1537,7 +1544,7 @@ void CertificateRequest::Build()
for (int j = 0; j < authCount; j++) {
int sz = REQUEST_HEADER + MIN_DIS_SIZE;
DistinguishedName dn;
certificate_authorities_.push_back(dn = new (ys) byte[sz]);
certificate_authorities_.push_back(dn = NEW_YS byte[sz]);
opaque tmp[REQUEST_HEADER];
c16toa(MIN_DIS_SIZE, tmp);
@ -1584,7 +1591,7 @@ input_buffer& operator>>(input_buffer& input, CertificateRequest& request)
ato16(tmp, dnSz);
DistinguishedName dn;
request.certificate_authorities_.push_back(dn = new (ys)
request.certificate_authorities_.push_back(dn = NEW_YS
byte[REQUEST_HEADER + dnSz]);
memcpy(dn, tmp, REQUEST_HEADER);
input.read(&dn[REQUEST_HEADER], dnSz);
@ -1630,7 +1637,11 @@ output_buffer& operator<<(output_buffer& output,
// CertificateRequest processing handler
void CertificateRequest::Process(input_buffer&, SSL& ssl)
{
ssl.useCrypto().use_certManager().setSendVerify();
CertManager& cm = ssl.useCrypto().use_certManager();
// make sure user provided cert and key before sending and using
if (cm.get_cert() && cm.get_privateKey())
cm.setSendVerify();
}
@ -1665,7 +1676,7 @@ void CertificateVerify::Build(SSL& ssl)
RSA rsa(cert.get_privateKey(), cert.get_privateKeyLength(), false);
sz = rsa.get_cipherLength() + VERIFY_HEADER;
sig.reset(new (ys) byte[sz]);
sig.reset(NEW_YS byte[sz]);
c16toa(sz - VERIFY_HEADER, len);
memcpy(sig.get(), len, VERIFY_HEADER);
@ -1676,7 +1687,7 @@ void CertificateVerify::Build(SSL& ssl)
DSS dss(cert.get_privateKey(), cert.get_privateKeyLength(), false);
sz = DSS_SIG_SZ + DSS_ENCODED_EXTRA + VERIFY_HEADER;
sig.reset(new (ys) byte[sz]);
sig.reset(NEW_YS byte[sz]);
c16toa(sz - VERIFY_HEADER, len);
memcpy(sig.get(), len, VERIFY_HEADER);
@ -1714,7 +1725,7 @@ input_buffer& operator>>(input_buffer& input, CertificateVerify& request)
ato16(tmp, sz);
request.set_length(sz);
request.signature_ = new (ys) byte[sz];
request.signature_ = NEW_YS byte[sz];
input.read(request.signature_, sz);
return input;
@ -1975,7 +1986,7 @@ Connection::~Connection()
void Connection::AllocPreSecret(uint sz)
{
pre_master_secret_ = new (ys) opaque[pre_secret_len_ = sz];
pre_master_secret_ = NEW_YS opaque[pre_secret_len_ = sz];
}
@ -2011,35 +2022,35 @@ void Connection::CleanPreMaster()
// Create functions for message factory
Message* CreateCipherSpec() { return new (ys) ChangeCipherSpec; }
Message* CreateAlert() { return new (ys) Alert; }
Message* CreateHandShake() { return new (ys) HandShakeHeader; }
Message* CreateData() { return new (ys) Data; }
Message* CreateCipherSpec() { return NEW_YS ChangeCipherSpec; }
Message* CreateAlert() { return NEW_YS Alert; }
Message* CreateHandShake() { return NEW_YS HandShakeHeader; }
Message* CreateData() { return NEW_YS Data; }
// Create functions for handshake factory
HandShakeBase* CreateHelloRequest() { return new (ys) HelloRequest; }
HandShakeBase* CreateClientHello() { return new (ys) ClientHello; }
HandShakeBase* CreateServerHello() { return new (ys) ServerHello; }
HandShakeBase* CreateCertificate() { return new (ys) Certificate; }
HandShakeBase* CreateServerKeyExchange() { return new (ys) ServerKeyExchange;}
HandShakeBase* CreateCertificateRequest() { return new (ys)
HandShakeBase* CreateHelloRequest() { return NEW_YS HelloRequest; }
HandShakeBase* CreateClientHello() { return NEW_YS ClientHello; }
HandShakeBase* CreateServerHello() { return NEW_YS ServerHello; }
HandShakeBase* CreateCertificate() { return NEW_YS Certificate; }
HandShakeBase* CreateServerKeyExchange() { return NEW_YS ServerKeyExchange;}
HandShakeBase* CreateCertificateRequest() { return NEW_YS
CertificateRequest; }
HandShakeBase* CreateServerHelloDone() { return new (ys) ServerHelloDone; }
HandShakeBase* CreateCertificateVerify() { return new (ys) CertificateVerify;}
HandShakeBase* CreateClientKeyExchange() { return new (ys) ClientKeyExchange;}
HandShakeBase* CreateFinished() { return new (ys) Finished; }
HandShakeBase* CreateServerHelloDone() { return NEW_YS ServerHelloDone; }
HandShakeBase* CreateCertificateVerify() { return NEW_YS CertificateVerify;}
HandShakeBase* CreateClientKeyExchange() { return NEW_YS ClientKeyExchange;}
HandShakeBase* CreateFinished() { return NEW_YS Finished; }
// Create functions for server key exchange factory
ServerKeyBase* CreateRSAServerKEA() { return new (ys) RSA_Server; }
ServerKeyBase* CreateDHServerKEA() { return new (ys) DH_Server; }
ServerKeyBase* CreateFortezzaServerKEA() { return new (ys) Fortezza_Server; }
ServerKeyBase* CreateRSAServerKEA() { return NEW_YS RSA_Server; }
ServerKeyBase* CreateDHServerKEA() { return NEW_YS DH_Server; }
ServerKeyBase* CreateFortezzaServerKEA() { return NEW_YS Fortezza_Server; }
// Create functions for client key exchange factory
ClientKeyBase* CreateRSAClient() { return new (ys)
ClientKeyBase* CreateRSAClient() { return NEW_YS
EncryptedPreMasterSecret; }
ClientKeyBase* CreateDHClient() { return new (ys)
ClientKeyBase* CreateDHClient() { return NEW_YS
ClientDiffieHellmanPublic; }
ClientKeyBase* CreateFortezzaClient() { return new (ys) FortezzaKeys; }
ClientKeyBase* CreateFortezzaClient() { return NEW_YS FortezzaKeys; }
// Constructor calls this to Register compile time callbacks

View File

@ -31,26 +31,20 @@
#include "openssl/ssl.h" // for DH
#ifdef YASSL_PURE_C
void* operator new(size_t sz, yaSSL::new_t)
{
#ifdef YASSL_PURE_C
void* ptr = malloc(sz ? sz : 1);
if (!ptr) abort();
return ptr;
#else
return ::operator new(sz);
#endif
}
void operator delete(void* ptr, yaSSL::new_t)
{
#ifdef YASSL_PURE_C
if (ptr) free(ptr);
#else
::operator delete(ptr);
#endif
}
@ -65,6 +59,13 @@ void operator delete[](void* ptr, yaSSL::new_t nt)
::operator delete(ptr, nt);
}
namespace yaSSL {
new_t ys; // for yaSSL library new
}
#endif // YASSL_PURE_C
namespace yaSSL {
@ -72,7 +73,6 @@ namespace yaSSL {
using mySTL::min;
new_t ys; // for yaSSL library new
@ -286,6 +286,8 @@ SSL::SSL(SSL_CTX* ctx)
if (ctx->getMethod()->verifyPeer())
cm.setVerifyPeer();
if (ctx->getMethod()->verifyNone())
cm.setVerifyNone();
if (ctx->getMethod()->failNoCert())
cm.setFailNoCert();
@ -321,8 +323,8 @@ void SSL::set_pending(Cipher suite)
parms.key_size_ = AES_256_KEY_SZ;
parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block;
crypto_.setDigest(new (ys) SHA);
crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ));
crypto_.setDigest(NEW_YS SHA);
crypto_.setCipher(NEW_YS AES(AES_256_KEY_SZ));
strncpy(parms.cipher_name_, cipher_names[TLS_RSA_WITH_AES_256_CBC_SHA],
MAX_SUITE_NAME);
break;
@ -335,8 +337,8 @@ void SSL::set_pending(Cipher suite)
parms.key_size_ = AES_128_KEY_SZ;
parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block;
crypto_.setDigest(new (ys) SHA);
crypto_.setCipher(new (ys) AES);
crypto_.setDigest(NEW_YS SHA);
crypto_.setCipher(NEW_YS AES);
strncpy(parms.cipher_name_, cipher_names[TLS_RSA_WITH_AES_128_CBC_SHA],
MAX_SUITE_NAME);
break;
@ -349,8 +351,8 @@ void SSL::set_pending(Cipher suite)
parms.key_size_ = DES_EDE_KEY_SZ;
parms.iv_size_ = DES_IV_SZ;
parms.cipher_type_ = block;
crypto_.setDigest(new (ys) SHA);
crypto_.setCipher(new (ys) DES_EDE);
crypto_.setDigest(NEW_YS SHA);
crypto_.setCipher(NEW_YS DES_EDE);
strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_3DES_EDE_CBC_SHA]
, MAX_SUITE_NAME);
break;
@ -363,8 +365,8 @@ void SSL::set_pending(Cipher suite)
parms.key_size_ = DES_KEY_SZ;
parms.iv_size_ = DES_IV_SZ;
parms.cipher_type_ = block;
crypto_.setDigest(new (ys) SHA);
crypto_.setCipher(new (ys) DES);
crypto_.setDigest(NEW_YS SHA);
crypto_.setCipher(NEW_YS DES);
strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_DES_CBC_SHA],
MAX_SUITE_NAME);
break;
@ -377,8 +379,8 @@ void SSL::set_pending(Cipher suite)
parms.key_size_ = RC4_KEY_SZ;
parms.iv_size_ = 0;
parms.cipher_type_ = stream;
crypto_.setDigest(new (ys) SHA);
crypto_.setCipher(new (ys) RC4);
crypto_.setDigest(NEW_YS SHA);
crypto_.setCipher(NEW_YS RC4);
strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_RC4_128_SHA],
MAX_SUITE_NAME);
break;
@ -391,8 +393,8 @@ void SSL::set_pending(Cipher suite)
parms.key_size_ = RC4_KEY_SZ;
parms.iv_size_ = 0;
parms.cipher_type_ = stream;
crypto_.setDigest(new (ys) MD5);
crypto_.setCipher(new (ys) RC4);
crypto_.setDigest(NEW_YS MD5);
crypto_.setCipher(NEW_YS RC4);
strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_RC4_128_MD5],
MAX_SUITE_NAME);
break;
@ -407,8 +409,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = DES_IV_SZ;
parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) SHA);
crypto_.setCipher(new (ys) DES);
crypto_.setDigest(NEW_YS SHA);
crypto_.setCipher(NEW_YS DES);
strncpy(parms.cipher_name_, cipher_names[SSL_DHE_RSA_WITH_DES_CBC_SHA],
MAX_SUITE_NAME);
break;
@ -423,8 +425,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = DES_IV_SZ;
parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) SHA);
crypto_.setCipher(new (ys) DES_EDE);
crypto_.setDigest(NEW_YS SHA);
crypto_.setCipher(NEW_YS DES_EDE);
strncpy(parms.cipher_name_,
cipher_names[SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA], MAX_SUITE_NAME);
break;
@ -439,8 +441,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) SHA);
crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ));
crypto_.setDigest(NEW_YS SHA);
crypto_.setCipher(NEW_YS AES(AES_256_KEY_SZ));
strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_RSA_WITH_AES_256_CBC_SHA], MAX_SUITE_NAME);
break;
@ -455,8 +457,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) SHA);
crypto_.setCipher(new (ys) AES);
crypto_.setDigest(NEW_YS SHA);
crypto_.setCipher(NEW_YS AES);
strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_RSA_WITH_AES_128_CBC_SHA], MAX_SUITE_NAME);
break;
@ -471,8 +473,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = DES_IV_SZ;
parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) SHA);
crypto_.setCipher(new (ys) DES);
crypto_.setDigest(NEW_YS SHA);
crypto_.setCipher(NEW_YS DES);
strncpy(parms.cipher_name_, cipher_names[SSL_DHE_DSS_WITH_DES_CBC_SHA],
MAX_SUITE_NAME);
break;
@ -487,8 +489,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = DES_IV_SZ;
parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) SHA);
crypto_.setCipher(new (ys) DES_EDE);
crypto_.setDigest(NEW_YS SHA);
crypto_.setCipher(NEW_YS DES_EDE);
strncpy(parms.cipher_name_,
cipher_names[SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA], MAX_SUITE_NAME);
break;
@ -503,8 +505,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) SHA);
crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ));
crypto_.setDigest(NEW_YS SHA);
crypto_.setCipher(NEW_YS AES(AES_256_KEY_SZ));
strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_DSS_WITH_AES_256_CBC_SHA], MAX_SUITE_NAME);
break;
@ -519,8 +521,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) SHA);
crypto_.setCipher(new (ys) AES);
crypto_.setDigest(NEW_YS SHA);
crypto_.setCipher(NEW_YS AES);
strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_DSS_WITH_AES_128_CBC_SHA], MAX_SUITE_NAME);
break;
@ -533,8 +535,8 @@ void SSL::set_pending(Cipher suite)
parms.key_size_ = AES_256_KEY_SZ;
parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block;
crypto_.setDigest(new (ys) RMD);
crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ));
crypto_.setDigest(NEW_YS RMD);
crypto_.setCipher(NEW_YS AES(AES_256_KEY_SZ));
strncpy(parms.cipher_name_,
cipher_names[TLS_RSA_WITH_AES_256_CBC_RMD160], MAX_SUITE_NAME);
break;
@ -547,8 +549,8 @@ void SSL::set_pending(Cipher suite)
parms.key_size_ = AES_128_KEY_SZ;
parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block;
crypto_.setDigest(new (ys) RMD);
crypto_.setCipher(new (ys) AES);
crypto_.setDigest(NEW_YS RMD);
crypto_.setCipher(NEW_YS AES);
strncpy(parms.cipher_name_,
cipher_names[TLS_RSA_WITH_AES_128_CBC_RMD160], MAX_SUITE_NAME);
break;
@ -561,8 +563,8 @@ void SSL::set_pending(Cipher suite)
parms.key_size_ = DES_EDE_KEY_SZ;
parms.iv_size_ = DES_IV_SZ;
parms.cipher_type_ = block;
crypto_.setDigest(new (ys) RMD);
crypto_.setCipher(new (ys) DES_EDE);
crypto_.setDigest(NEW_YS RMD);
crypto_.setCipher(NEW_YS DES_EDE);
strncpy(parms.cipher_name_,
cipher_names[TLS_RSA_WITH_3DES_EDE_CBC_RMD160], MAX_SUITE_NAME);
break;
@ -577,8 +579,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = DES_IV_SZ;
parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) RMD);
crypto_.setCipher(new (ys) DES_EDE);
crypto_.setDigest(NEW_YS RMD);
crypto_.setCipher(NEW_YS DES_EDE);
strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_RSA_WITH_3DES_EDE_CBC_RMD160],
MAX_SUITE_NAME);
@ -594,8 +596,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) RMD);
crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ));
crypto_.setDigest(NEW_YS RMD);
crypto_.setCipher(NEW_YS AES(AES_256_KEY_SZ));
strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_RSA_WITH_AES_256_CBC_RMD160],
MAX_SUITE_NAME);
@ -611,8 +613,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) RMD);
crypto_.setCipher(new (ys) AES);
crypto_.setDigest(NEW_YS RMD);
crypto_.setCipher(NEW_YS AES);
strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_RSA_WITH_AES_128_CBC_RMD160],
MAX_SUITE_NAME);
@ -628,8 +630,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = DES_IV_SZ;
parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) RMD);
crypto_.setCipher(new (ys) DES_EDE);
crypto_.setDigest(NEW_YS RMD);
crypto_.setCipher(NEW_YS DES_EDE);
strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_DSS_WITH_3DES_EDE_CBC_RMD160],
MAX_SUITE_NAME);
@ -645,8 +647,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) RMD);
crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ));
crypto_.setDigest(NEW_YS RMD);
crypto_.setCipher(NEW_YS AES(AES_256_KEY_SZ));
strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_DSS_WITH_AES_256_CBC_RMD160],
MAX_SUITE_NAME);
@ -662,8 +664,8 @@ void SSL::set_pending(Cipher suite)
parms.iv_size_ = AES_BLOCK_SZ;
parms.cipher_type_ = block;
secure_.use_connection().send_server_key_ = true; // eph
crypto_.setDigest(new (ys) RMD);
crypto_.setCipher(new (ys) AES);
crypto_.setDigest(NEW_YS RMD);
crypto_.setCipher(NEW_YS AES);
strncpy(parms.cipher_name_,
cipher_names[TLS_DHE_DSS_WITH_AES_128_CBC_RMD160],
MAX_SUITE_NAME);
@ -830,7 +832,7 @@ void SSL::deriveKeys()
int length = 2 * secure_.get_parms().hash_size_ +
2 * secure_.get_parms().key_size_ +
2 * secure_.get_parms().iv_size_;
int rounds = length / MD5_LEN + ((length % MD5_LEN) ? 1 : 0);
int rounds = (length + MD5_LEN - 1 ) / MD5_LEN;
input_buffer key_data(rounds * MD5_LEN);
opaque sha_output[SHA_LEN];
@ -1366,17 +1368,16 @@ static Sessions* sessionsInstance = 0;
Sessions& GetSessions()
{
if (!sessionsInstance)
sessionsInstance = new (ys) Sessions;
sessionsInstance = NEW_YS Sessions;
return *sessionsInstance;
}
static sslFactory* sslFactoryInstance = 0;
sslFactory& GetSSL_Factory()
{
sslFactory& GetSSL_Factory(){
if (!sslFactoryInstance)
sslFactoryInstance = new (ys) sslFactory;
sslFactoryInstance = NEW_YS sslFactory;
return *sslFactoryInstance;
}
@ -1395,7 +1396,7 @@ typedef Mutex::Lock Lock;
void Sessions::add(const SSL& ssl)
{
Lock guard(mutex_);
list_.push_back(new (ys) SSL_SESSION(ssl, random_));
list_.push_back(NEW_YS SSL_SESSION(ssl, random_));
}
@ -1462,7 +1463,8 @@ void Sessions::remove(const opaque* id)
SSL_METHOD::SSL_METHOD(ConnectionEnd ce, ProtocolVersion pv)
: version_(pv), side_(ce), verifyPeer_(false), failNoCert_(false)
: version_(pv), side_(ce), verifyPeer_(false), verifyNone_(false),
failNoCert_(false)
{}
@ -1484,6 +1486,12 @@ void SSL_METHOD::setVerifyPeer()
}
void SSL_METHOD::setVerifyNone()
{
verifyNone_ = true;
}
void SSL_METHOD::setFailNoCert()
{
failNoCert_ = true;
@ -1496,6 +1504,12 @@ bool SSL_METHOD::verifyPeer() const
}
bool SSL_METHOD::verifyNone() const
{
return verifyNone_;
}
bool SSL_METHOD::failNoCert() const
{
return failNoCert_;
@ -1572,6 +1586,12 @@ void SSL_CTX::setVerifyPeer()
}
void SSL_CTX::setVerifyNone()
{
method_->setVerifyNone();
}
void SSL_CTX::setFailNoCert()
{
method_->setFailNoCert();
@ -1794,7 +1814,7 @@ void Crypto::SetDH(DiffieHellman* dh)
void Crypto::SetDH(const DH_Parms& dh)
{
if (dh.set_)
dh_ = new (ys) DiffieHellman(dh.p_, dh.g_, random_);
dh_ = NEW_YS DiffieHellman(dh.p_, dh.g_, random_);
}
@ -1961,7 +1981,7 @@ X509_NAME::X509_NAME(const char* n, size_t sz)
: name_(0)
{
if (sz) {
name_ = new (ys) char[sz];
name_ = NEW_YS char[sz];
memcpy(name_, n, sz);
}
}

View File

@ -1,2 +1,2 @@
SUBDIRS = src
SUBDIRS = src test benchmark
EXTRA_DIST = taocrypt.dsw taocrypt.dsp taocrypt.vcproj cmakelists.txt

View File

@ -0,0 +1,8 @@
INCLUDES = -I../include -I../../mySTL
bin_PROGRAMS = benchmark
benchmark_SOURCES = benchmark.cpp
benchmark_LDFLAGS = -L../src
benchmark_LDADD = -ltaocrypt
benchmark_CXXFLAGS = -DYASSL_PURE_C
benchmark_DEPENDENCIES = ../src/libtaocrypt.la
EXTRA_DIST = benchmark.dsp rsa1024.der dh1024.der dsa1024.der make.bat

View File

@ -0,0 +1,440 @@
// benchmark.cpp
// TaoCrypt benchmark
#include <string.h>
#include <stdio.h>
#include "runtime.hpp"
#include "des.hpp"
#include "aes.hpp"
#include "twofish.hpp"
#include "blowfish.hpp"
#include "arc4.hpp"
#include "md5.hpp"
#include "sha.hpp"
#include "ripemd.hpp"
#include "rsa.hpp"
#include "dh.hpp"
#include "dsa.hpp"
using namespace TaoCrypt;
void bench_aes(bool show);
void bench_des();
void bench_blowfish();
void bench_twofish();
void bench_arc4();
void bench_md5();
void bench_sha();
void bench_ripemd();
void bench_rsa();
void bench_dh();
void bench_dsa();
double current_time();
int main(int argc, char** argv)
{
bench_aes(false);
bench_aes(true);
bench_blowfish();
bench_twofish();
bench_arc4();
bench_des();
printf("\n");
bench_md5();
bench_sha();
bench_ripemd();
printf("\n");
bench_rsa();
bench_dh();
bench_dsa();
return 0;
}
const int megs = 5; // how much to test
const byte key[] =
{
0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
};
const byte iv[] =
{
0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
};
byte plain [1024*1024];
byte cipher[1024*1024];
void bench_des()
{
DES_EDE3_CBC_Encryption enc;
enc.SetKey(key, 16, iv);
double start = current_time();
for(int i = 0; i < megs; i++)
enc.Process(plain, cipher, sizeof(plain));
double total = current_time() - start;
double persec = 1 / total * megs;
printf("3DES %d megs took %5.3f seconds, %5.2f MB/s\n", megs, total,
persec);
}
void bench_aes(bool show)
{
AES_CBC_Encryption enc;
enc.SetKey(key, 16, iv);
double start = current_time();
for(int i = 0; i < megs; i++)
enc.Process(plain, cipher, sizeof(plain));
double total = current_time() - start;
double persec = 1 / total * megs;
if (show)
printf("AES %d megs took %5.3f seconds, %5.2f MB/s\n", megs, total,
persec);
}
void bench_twofish()
{
Twofish_CBC_Encryption enc;
enc.SetKey(key, 16, iv);
double start = current_time();
for(int i = 0; i < megs; i++)
enc.Process(plain, cipher, sizeof(plain));
double total = current_time() - start;
double persec = 1 / total * megs;
printf("Twofish %d megs took %5.3f seconds, %5.2f MB/s\n", megs, total,
persec);
}
void bench_blowfish()
{
Blowfish_CBC_Encryption enc;
enc.SetKey(key, 16, iv);
double start = current_time();
for(int i = 0; i < megs; i++)
enc.Process(plain, cipher, sizeof(plain));
double total = current_time() - start;
double persec = 1 / total * megs;
printf("Blowfish %d megs took %5.3f seconds, %5.2f MB/s\n", megs, total,
persec);
}
void bench_arc4()
{
ARC4 enc;
enc.SetKey(key, 16);
double start = current_time();
for(int i = 0; i < megs; i++)
enc.Process(cipher, plain, sizeof(plain));
double total = current_time() - start;
double persec = 1 / total * megs;
printf("ARC4 %d megs took %5.3f seconds, %5.2f MB/s\n", megs, total,
persec);
}
void bench_md5()
{
MD5 hash;
byte digest[MD5::DIGEST_SIZE];
double start = current_time();
for(int i = 0; i < megs; i++)
hash.Update(plain, sizeof(plain));
hash.Final(digest);
double total = current_time() - start;
double persec = 1 / total * megs;
printf("MD5 %d megs took %5.3f seconds, %5.2f MB/s\n", megs, total,
persec);
}
void bench_sha()
{
SHA hash;
byte digest[SHA::DIGEST_SIZE];
double start = current_time();
for(int i = 0; i < megs; i++)
hash.Update(plain, sizeof(plain));
hash.Final(digest);
/*
for(int i = 0; i < megs; i++)
hash.AsmTransform(plain, 16384);
*/
double total = current_time() - start;
double persec = 1 / total * megs;
printf("SHA %d megs took %5.3f seconds, %5.2f MB/s\n", megs, total,
persec);
}
void bench_ripemd()
{
RIPEMD160 hash;
byte digest[RIPEMD160::DIGEST_SIZE];
double start = current_time();
for(int i = 0; i < megs; i++)
hash.Update(plain, sizeof(plain));
hash.Final(digest);
double total = current_time() - start;
double persec = 1 / total * megs;
printf("RIPEMD %d megs took %5.3f seconds, %5.2f MB/s\n", megs, total,
persec);
}
RandomNumberGenerator rng;
void bench_rsa()
{
const int times = 100;
Source source;
FileSource("./rsa1024.der", source);
if (source.size() == 0) {
printf("can't find ./rsa1024.der\n");
return;
}
RSA_PrivateKey priv(source);
RSAES_Encryptor enc(priv);
byte message[] = "Everyone gets Friday off.";
byte cipher[128]; // for 1024 bit
byte plain[128]; // for 1024 bit
const int len = strlen((char*)message);
int i;
double start = current_time();
for (i = 0; i < times; i++)
enc.Encrypt(message, len, cipher, rng);
double total = current_time() - start;
double each = total / times; // per second
double milliEach = each * 1000; // milliseconds
printf("RSA 1024 encryption took %6.2f milliseconds, avg over %d"
" iterations\n", milliEach, times);
RSAES_Decryptor dec(priv);
start = current_time();
for (i = 0; i < times; i++)
dec.Decrypt(cipher, 128, plain, rng);
total = current_time() - start;
each = total / times; // per second
milliEach = each * 1000; // milliseconds
printf("RSA 1024 decryption took %6.2f milliseconds, avg over %d"
" iterations\n", milliEach, times);
}
void bench_dh()
{
const int times = 100;
Source source;
FileSource("./dh1024.der", source);
if (source.size() == 0) {
printf("can't find ./dh1024.der\n");
return;
}
DH dh(source);
byte pub[128]; // for 1024 bit
byte priv[128]; // for 1024 bit
int i;
double start = current_time();
for (i = 0; i < times; i++)
dh.GenerateKeyPair(rng, priv, pub);
double total = current_time() - start;
double each = total / times; // per second
double milliEach = each * 1000; // milliseconds
printf("DH 1024 key generation %6.2f milliseconds, avg over %d"
" iterations\n", milliEach, times);
DH dh2(dh);
byte pub2[128]; // for 1024 bit
byte priv2[128]; // for 1024 bit
dh2.GenerateKeyPair(rng, priv2, pub2);
unsigned char key[256];
start = current_time();
for (i = 0; i < times; i++)
dh.Agree(key, priv, pub2);
total = current_time() - start;
each = total / times; // per second
milliEach = each * 1000; // in milliseconds
printf("DH 1024 key agreement %6.2f milliseconds, avg over %d"
" iterations\n", milliEach, times);
}
void bench_dsa()
{
const int times = 100;
Source source;
FileSource("./dsa1024.der", source);
if (source.size() == 0) {
printf("can't find ./dsa1024.der\n");
return;
}
DSA_PrivateKey key(source);
DSA_Signer signer(key);
SHA sha;
byte digest[SHA::DIGEST_SIZE];
byte signature[40];
const char msg[] = "this is the message";
sha.Update((byte*)msg, sizeof(msg));
sha.Final(digest);
int i;
double start = current_time();
for (i = 0; i < times; i++)
signer.Sign(digest, signature, rng);
double total = current_time() - start;
double each = total / times; // per second
double milliEach = each * 1000; // milliseconds
printf("DSA 1024 sign took %6.2f milliseconds, avg over %d"
" iterations\n", milliEach, times);
DSA_Verifier verifier(key);
start = current_time();
for (i = 0; i < times; i++)
verifier.Verify(digest, signature);
total = current_time() - start;
each = total / times; // per second
milliEach = each * 1000; // in milliseconds
printf("DSA 1024 verify took %6.2f milliseconds, avg over %d"
" iterations\n", milliEach, times);
}
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
double current_time()
{
static bool init(false);
static LARGE_INTEGER freq;
if (!init) {
QueryPerformanceFrequency(&freq);
init = true;
}
LARGE_INTEGER count;
QueryPerformanceCounter(&count);
return static_cast<double>(count.QuadPart) / freq.QuadPart;
}
#else
#include <sys/time.h>
double current_time()
{
struct timeval tv;
gettimeofday(&tv, 0);
return static_cast<double>(tv.tv_sec)
+ static_cast<double>(tv.tv_usec) / 1000000;
}
#endif // _WIN32

View File

@ -0,0 +1,101 @@
# Microsoft Developer Studio Project File - Name="benchmark" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=benchmark - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "benchmark.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "benchmark.mak" CFG="benchmark - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "benchmark - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "benchmark - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "benchmark - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "benchmark___Win32_Release"
# PROP BASE Intermediate_Dir "benchmark___Win32_Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\include" /I "..\..\mySTL" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "benchmark - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "benchmark___Win32_Debug"
# PROP BASE Intermediate_Dir "benchmark___Win32_Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\include" /I "..\..\mySTL" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "benchmark - Win32 Release"
# Name "benchmark - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\benchmark.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,10 @@
# quick and dirty build file for testing different MSDEVs
setlocal
set myFLAGS= /I../include /I../../mySTL /c /W3 /G6 /O2
#set myFLAGS= /I../include /I../../mySTL /c /W3
cl %myFLAGS% benchmark.cpp
link.exe /out:benchmark.exe ../src/taocrypt.lib benchmark.obj

Binary file not shown.

View File

@ -26,13 +26,13 @@
#ifndef TAO_CRYPT_AES_HPP
#define TAO_CRYPT_AES_HPP
#include <string.h>
#include "misc.hpp"
#include "modes.hpp"
#include "block.hpp"
namespace TaoCrypt {
enum { AES_BLOCK_SIZE = 16 };
@ -45,32 +45,38 @@ public:
: Mode_BASE(BLOCK_SIZE), dir_(DIR), mode_(MODE) {}
void Process(byte*, const byte*, word32);
void SetKey(const byte* iv, word32 sz, CipherDir fake = ENCRYPTION);
void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
void SetKey(const byte* key, word32 sz, CipherDir fake = ENCRYPTION);
void SetIV(const byte* iv) { memcpy(r_, iv, BLOCK_SIZE); }
private:
CipherDir dir_;
Mode mode_;
static const word32 Te0[256];
static const word32 Te1[256];
static const word32 Te2[256];
static const word32 Te3[256];
static const word32 Te4[256];
static const word32 Td0[256];
static const word32 Td1[256];
static const word32 Td2[256];
static const word32 Td3[256];
static const word32 Td4[256];
static const word32 rcon_[];
word32 rounds_;
Word32Block key_;
word32 key_[60]; // max size
static const word32 Te[5][256];
static const word32 Td[5][256];
static const word32* Te0;
static const word32* Te1;
static const word32* Te2;
static const word32* Te3;
static const word32* Te4;
static const word32* Td0;
static const word32* Td1;
static const word32* Td2;
static const word32* Td3;
static const word32* Td4;
void encrypt(const byte*, const byte*, byte*) const;
void AsmEncrypt(const byte*, byte*, void*) const;
void decrypt(const byte*, const byte*, byte*) const;
void AsmDecrypt(const byte*, byte*, void*) const;
void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
AES(const AES&); // hide copy
AES& operator=(const AES&); // and assign

View File

@ -42,6 +42,7 @@ public:
ARC4() {}
void Process(byte*, const byte*, word32);
void AsmProcess(byte*, const byte*, word32);
void SetKey(const byte*, word32);
private:
byte x_;

View File

@ -232,7 +232,12 @@ enum KeyType { DSAk = 515, RSAk = 645 }; // sums of algo OID
// an x509v Certificate BER Decoder
class CertDecoder : public BER_Decoder {
public:
explicit CertDecoder(Source&, bool decode = true, SignerList* = 0);
enum DateType { BEFORE, AFTER };
enum NameType { ISSUER, SUBJECT };
enum CertType { CA, USER };
explicit CertDecoder(Source&, bool decode = true, SignerList* sl = 0,
bool noVerify = false, CertType ct = USER);
~CertDecoder();
const PublicKey& GetPublicKey() const { return key_; }
@ -242,9 +247,6 @@ public:
const byte* GetHash() const { return subjectHash_; }
void DecodeToKey();
enum DateType { BEFORE, AFTER };
enum NameType { ISSUER, SUBJECT };
private:
PublicKey key_;
word32 certBegin_; // offset to start of cert
@ -257,9 +259,10 @@ private:
byte* signature_;
char* issuer_; // CommonName
char* subject_; // CommonName
bool verify_; // Default to yes, but could be off
void ReadHeader();
void Decode(SignerList*);
void Decode(SignerList*, CertType);
void StoreKey();
void AddDSA();
bool ValidateSelfSignature();

View File

@ -99,7 +99,7 @@ public:
CheckSize(n);
if (n == 0)
return 0;
return new (tc) T[n];
return NEW_TC T[n];
}
void deallocate(void* p, size_type n)

View File

@ -0,0 +1,79 @@
/* blowfish.hpp
*
* Copyright (C) 2003 Sawtooth Consulting Ltd.
*
* This file is part of yaSSL.
*
* yaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* yaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/* blowfish.hpp defines Blowfish
*/
#ifndef TAO_CRYPT_BLOWFISH_HPP
#define TAO_CRYPT_BLOWFISH_HPP
#include "misc.hpp"
#include "modes.hpp"
#include "algorithm.hpp"
namespace TaoCrypt {
enum { BLOWFISH_BLOCK_SIZE = 8 };
// Blowfish encryption and decryption, see
class Blowfish : public Mode_BASE {
public:
enum { BLOCK_SIZE = BLOWFISH_BLOCK_SIZE, ROUNDS = 16 };
Blowfish(CipherDir DIR, Mode MODE)
: Mode_BASE(BLOCK_SIZE), dir_(DIR), mode_(MODE) {}
void Process(byte*, const byte*, word32);
void SetKey(const byte* key, word32 sz, CipherDir fake = ENCRYPTION);
void SetIV(const byte* iv) { memcpy(r_, iv, BLOCK_SIZE); }
private:
CipherDir dir_;
Mode mode_;
static const word32 p_init_[ROUNDS + 2];
static const word32 s_init_[4 * 256];
word32 pbox_[ROUNDS + 2];
word32 sbox_[4 * 256];
void crypt_block(const word32 in[2], word32 out[2]) const;
void AsmProcess(const byte* in, byte* out) const;
void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
Blowfish(const Blowfish&); // hide copy
Blowfish& operator=(const Blowfish&); // and assign
};
typedef BlockCipher<ENCRYPTION, Blowfish, ECB> Blowfish_ECB_Encryption;
typedef BlockCipher<DECRYPTION, Blowfish, ECB> Blowfish_ECB_Decryption;
typedef BlockCipher<ENCRYPTION, Blowfish, CBC> Blowfish_CBC_Encryption;
typedef BlockCipher<DECRYPTION, Blowfish, CBC> Blowfish_CBC_Decryption;
} // naemspace
#endif // TAO_CRYPT_BLOWFISH_HPP

View File

@ -27,73 +27,87 @@
#ifndef TAO_CRYPT_DES_HPP
#define TAO_CRYPT_DES_HPP
#include <string.h>
#include "misc.hpp"
#include "modes.hpp"
namespace TaoCrypt {
enum { DES_BLOCK_SIZE = 8 };
// Base for all DES types
class DES_BASE : public Mode_BASE {
enum { DES_BLOCK_SIZE = 8, DES_KEY_SIZE = 32 };
class BasicDES {
public:
enum { BLOCK_SIZE = DES_BLOCK_SIZE, KEY_SIZE = 32, BOXES = 8,
BOX_SIZE = 64 };
DES_BASE(CipherDir DIR, Mode MODE)
: Mode_BASE(BLOCK_SIZE), dir_(DIR), mode_(MODE) {}
void Process(byte*, const byte*, word32);
void SetKey(const byte*, word32, CipherDir dir);
void RawProcessBlock(word32&, word32&) const;
protected:
CipherDir dir_;
Mode mode_;
private:
DES_BASE(const DES_BASE&); // hide copy
DES_BASE& operator=(const DES_BASE&); // and assign
word32 k_[DES_KEY_SIZE];
};
// DES
class DES : public DES_BASE {
class DES : public Mode_BASE, public BasicDES {
public:
DES(CipherDir DIR, Mode MODE) : DES_BASE(DIR, MODE) {}
DES(CipherDir DIR, Mode MODE)
: Mode_BASE(DES_BLOCK_SIZE), dir_(DIR), mode_(MODE) {}
void SetKey(const byte*, word32, CipherDir dir);
void RawProcessBlock(word32&, word32&) const;
void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
void Process(byte*, const byte*, word32);
private:
word32 k_[KEY_SIZE];
CipherDir dir_;
Mode mode_;
void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
DES(const DES&); // hide copy
DES& operator=(const DES&); // and assign
};
// DES_EDE2
class DES_EDE2 : public DES_BASE {
class DES_EDE2 : public Mode_BASE {
public:
DES_EDE2(CipherDir DIR, Mode MODE)
: DES_BASE(DIR, MODE), des1_(DIR, MODE), des2_(DIR, MODE) {}
: Mode_BASE(DES_BLOCK_SIZE), dir_(DIR), mode_(MODE) {}
void SetKey(const byte*, word32, CipherDir dir);
void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
void Process(byte*, const byte*, word32);
private:
DES des1_;
DES des2_;
CipherDir dir_;
Mode mode_;
BasicDES des1_;
BasicDES des2_;
void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
DES_EDE2(const DES_EDE2&); // hide copy
DES_EDE2& operator=(const DES_EDE2&); // and assign
};
// DES_EDE3
class DES_EDE3 : public DES_BASE {
class DES_EDE3 : public Mode_BASE {
public:
DES_EDE3(CipherDir DIR, Mode MODE)
: DES_BASE(DIR, MODE), des1_(DIR, MODE), des2_(DIR, MODE),
des3_(DIR, MODE) {}
: Mode_BASE(DES_BLOCK_SIZE), dir_(DIR), mode_(MODE) {}
void SetKey(const byte*, word32, CipherDir dir);
void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
void SetIV(const byte* iv) { memcpy(r_, iv, DES_BLOCK_SIZE); }
void Process(byte*, const byte*, word32);
private:
DES des1_;
DES des2_;
DES des3_;
CipherDir dir_;
Mode mode_;
BasicDES des1_;
BasicDES des2_;
BasicDES des3_;
void AsmProcess(const byte* in, byte* out, void* box) const;
void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
DES_EDE3(const DES_EDE3&); // hide copy
DES_EDE3& operator=(const DES_EDE3&); // and assign
};

View File

@ -64,7 +64,7 @@ public:
}
void GenerateKeyPair(RandomNumberGenerator&, byte*, byte*);
void Agree(byte*, const byte*, const byte*);
void Agree(byte*, const byte*, const byte*, word32 otherSz = 0);
void SetP(const Integer& p) { p_ = p; }
void SetG(const Integer& g) { g_ = g; }

View File

@ -57,17 +57,26 @@ public:
virtual void Update(const byte*, word32);
virtual void Final(byte*);
word32 GetBitCountLo() const { return loLen_ << 3; }
word32 GetBitCountHi() const { return (loLen_ >> (8*sizeof(loLen_) - 3)) +
(hiLen_ << 3); }
enum { MaxDigestSz = 5, MaxBufferSz = 64 };
protected:
word32 buffLen_;
word32 length_; // in Bits
typedef word32 HashLengthType;
word32 buffLen_; // in bytes
HashLengthType loLen_; // length in bytes
HashLengthType hiLen_; // length in bytes
word32 digest_[MaxDigestSz];
word32 buffer_[MaxBufferSz / sizeof(word32)];
virtual void Transform() = 0;
void AddLength(word32);
};
} // namespace
#endif // TAO_CRYPT_HASH_HPP

View File

@ -56,12 +56,12 @@ private:
T mac_;
// MSVC 6 HACK, gives compiler error if calculated in array
enum { HMAC_BSIZE = T::BLOCK_SIZE / sizeof(word32),
HMAC_DSIZE = T::DIGEST_SIZE / sizeof(word32) };
enum { BSIZE = T::BLOCK_SIZE / sizeof(word32),
DSIZE = T::DIGEST_SIZE / sizeof(word32) };
word32 ip_[HMAC_BSIZE]; // align ipad_ on word32
word32 op_[HMAC_BSIZE]; // align opad_ on word32
word32 innerH_[HMAC_DSIZE]; // align innerHash_ on word32
word32 ip_[BSIZE]; // align ipad_ on word32
word32 op_[BSIZE]; // align opad_ on word32
word32 innerH_[DSIZE]; // align innerHash_ on word32
void KeyInnerHash();

View File

@ -274,7 +274,6 @@ private:
Integer& dividend, const Integer& divisor);
AlignedWordBlock reg_;
Sign sign_;
};
inline bool operator==(const Integer& a, const Integer& b)

View File

@ -0,0 +1,49 @@
/* kernelc.hpp
*
* Copyright (C) 2003 Sawtooth Consulting Ltd.
*
* This file is part of yaSSL.
*
* yaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* yaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/* kernelc.hpp provides support for C std lib when compiled in kernel mode
*/
#ifndef TAOCRYPT_KERNELC_HPP
#define TAOCRYPT_KERNELC_HPP
#include <linux/types.h> // get right size_t
// system functions that c++ doesn't like headers for
extern "C" void* memcpy(void*, const void*, size_t);
extern "C" void* memset(void*, int, size_t);
extern "C" void printk(char *fmt, ...);
#define KERN_ERR "<3>" /* error conditions */
#if defined(NDEBUG)
#define assert(p) ((void)0)
#else
#define assert(expr) \
if (!(expr)) { \
printk(KERN_ERR "Assertion failed! %s,%s,%s,line=%d\n", \
#expr,__FILE__,__FUNCTION__,__LINE__); }
#endif
#endif // TAOCRYPT_KERNELC_HPP

View File

@ -45,10 +45,13 @@ public:
MD5(const MD5&);
MD5& operator= (const MD5&);
void Update(const byte*, word32);
void Init();
void Swap(MD5&);
private:
void Transform();
void AsmTransform(const byte* data, word32 times);
};
inline void swap(MD5& a, MD5& b)

View File

@ -24,9 +24,15 @@
#ifndef TAO_CRYPT_MISC_HPP
#define TAO_CRYPT_MISC_HPP
#if !defined(DO_TAOCRYPT_KERNEL_MODE)
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#else
#include "kernelc.hpp"
#endif
#include "types.hpp"
#include "type_traits.hpp"
@ -39,6 +45,8 @@ namespace TaoCrypt {
void CleanUp();
#ifdef YASSL_PURE_C
// library allocation
struct new_t {}; // TaoCrypt New type
extern new_t tc; // pass in parameter
@ -73,6 +81,8 @@ void tcArrayDelete(T* ptr)
::operator delete[](ptr, TaoCrypt::tc);
}
#define NEW_TC new (TaoCrypt::tc)
// to resolve compiler generated operator delete on base classes with
// virtual destructors (when on stack), make sure doesn't get called
@ -81,6 +91,28 @@ public:
static void operator delete(void*) { assert(0); }
};
#else // YASSL_PURE_C
template<typename T>
void tcDelete(T* ptr)
{
delete ptr;
}
template<typename T>
void tcArrayDelete(T* ptr)
{
delete[] ptr;
}
#define NEW_TC new
class virtual_base {};
#endif // YASSL_PURE_C
#if defined(_MSC_VER) || defined(__BCPLUSPLUS__)
#define INTEL_INTRINSICS
@ -100,15 +132,13 @@ public:
#define TAOCRYPT_DISABLE_X86ASM
#endif
// Disable assmebler when compiling with icc
// Temporary workaround for bug12717
// icc problem with -03 and integer, disable for now
#if defined(__INTEL_COMPILER)
#define TAOCRYPT_DISABLE_X86ASM
#endif
// Turn on ia32 ASM for Big Integer
// CodeWarrior defines _MSC_VER
#if !defined(TAOCRYPT_DISABLE_X86ASM) && ((defined(_MSC_VER) && \
!defined(__MWERKS__) && defined(_M_IX86)) || \
@ -117,6 +147,20 @@ public:
#endif
// Turn on ia32 ASM for Ciphers and Message Digests
// Seperate define since these are more complex, use member offsets
// and user may want to turn off while leaving Big Integer optos on
#if defined(TAOCRYPT_X86ASM_AVAILABLE) && !defined(DISABLE_TAO_ASM)
#define TAO_ASM
#endif
// Extra word in older vtable implementations, for ASM member offset
#if defined(__GNUC__) && __GNUC__ < 3
#define OLD_GCC_OFFSET
#endif
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
# define TAOCRYPT_MALLOC_ALIGNMENT_IS_16
#endif
@ -437,6 +481,58 @@ inline void ByteReverseIf(T* out, const T* in, word32 bc, ByteOrder order)
}
// do Asm Reverse is host is Little and x86asm
#ifdef LITTLE_ENDIAN_ORDER
#ifdef TAOCRYPT_X86ASM_AVAILABLE
#define LittleReverse AsmReverse
#else
#define LittleReverse ByteReverse
#endif
#else
#define LittleReverse
#endif
// do Asm Reverse is host is Big and x86asm
#ifdef BIG_ENDIAN_ORDER
#ifdef TAOCRYPT_X86ASM_AVAILABLE
#define BigReverse AsmReverse
#else
#define BigReverse ByteReverse
#endif
#else
#define BigReverse
#endif
#ifdef TAOCRYPT_X86ASM_AVAILABLE
// faster than rotate, use bswap
inline word32 AsmReverse(word32 wd)
{
#ifdef __GNUC__
__asm__
(
"bswap %1"
: "=r"(wd)
: "0"(wd)
);
#else
__asm
{
mov eax, wd
bswap eax
mov wd, eax
}
#endif
return wd;
}
#endif
template <class T>
inline void GetUserKey(ByteOrder order, T* out, word32 outlen, const byte* in,
word32 inlen)

View File

@ -26,7 +26,6 @@
#ifndef TAO_CRYPT_MODES_HPP
#define TAO_CRYPT_MODES_HPP
#include <string.h>
#include "misc.hpp"
namespace TaoCrypt {
@ -68,14 +67,8 @@ public:
}
virtual ~Mode_BASE() {}
virtual void ProcessAndXorBlock(const byte*, const byte*, byte*) const = 0;
void ECB_Process(byte*, const byte*, word32);
void CBC_Encrypt(byte*, const byte*, word32);
void CBC_Decrypt(byte*, const byte*, word32);
void SetIV(const byte* iv) { memcpy(reg_, iv, blockSz_); }
private:
protected:
int blockSz_;
byte* reg_;
byte* tmp_;
@ -83,9 +76,15 @@ private:
word32 r_[MaxBlockSz / sizeof(word32)]; // align reg_ on word32
word32 t_[MaxBlockSz / sizeof(word32)]; // align tmp_ on word32
void ECB_Process(byte*, const byte*, word32);
void CBC_Encrypt(byte*, const byte*, word32);
void CBC_Decrypt(byte*, const byte*, word32);
Mode_BASE(const Mode_BASE&); // hide copy
Mode_BASE& operator=(const Mode_BASE&); // and assign
private:
virtual void ProcessAndXorBlock(const byte*, const byte*, byte*) const = 0;
};

View File

@ -0,0 +1,93 @@
/* pwdbased.hpp
*
* Copyright (C) 2003 Sawtooth Consulting Ltd.
*
* This file is part of yaSSL.
*
* yaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* yaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/* pwdbased.hpp defines PBKDF2 from PKCS #5
*/
#ifndef TAO_CRYPT_PWDBASED_HPP
#define TAO_CRYPT_PWDBASED_HPP
#include <string.h>
#include "misc.hpp"
#include "block.hpp"
#include "hmac.hpp"
namespace TaoCrypt {
// From PKCS #5, T must be type suitable for HMAC<T>
template <class T>
class PBKDF2_HMAC {
public:
word32 MaxDerivedKeyLength() const { return 0xFFFFFFFFU;} // avoid overflow
word32 DeriveKey(byte* derived, word32 dLen, const byte* pwd, word32 pLen,
const byte* salt, word32 sLen, word32 iterations) const;
};
template <class T>
word32 PBKDF2_HMAC<T>::DeriveKey(byte* derived, word32 dLen, const byte* pwd,
word32 pLen, const byte* salt, word32 sLen,
word32 iterations) const
{
assert(dLen <= MaxDerivedKeyLength());
assert(iterations > 0);
ByteBlock buffer(T::DIGEST_SIZE);
HMAC<T> hmac;
hmac.SetKey(pwd, pLen);
word32 i = 1;
while (dLen > 0) {
hmac.Update(salt, sLen);
word32 j;
for (j = 0; j < 4; j++) {
byte b = i >> ((3-j)*8);
hmac.Update(&b, 1);
}
hmac.Final(buffer.get_buffer());
word32 segmentLen = mySTL::min(dLen, buffer.size());
memcpy(derived, buffer.get_buffer(), segmentLen);
for (j = 1; j < iterations; j++) {
hmac.Update(buffer.get_buffer(), buffer.size());
hmac.Final(buffer.get_buffer());
xorbuf(derived, buffer.get_buffer(), segmentLen);
}
derived += segmentLen;
dLen -= segmentLen;
i++;
}
return iterations;
}
} // naemspace
#endif // TAO_CRYPT_PWDBASED_HPP

View File

@ -45,10 +45,12 @@ public:
RIPEMD160(const RIPEMD160&);
RIPEMD160& operator= (const RIPEMD160&);
void Update(const byte*, word32);
void Init();
void Swap(RIPEMD160&);
private:
void Transform();
void AsmTransform(const byte* data, word32 times);
};
inline void swap(RIPEMD160& a, RIPEMD160& b)

View File

@ -49,7 +49,11 @@ namespace __Crun {
#if __GNUC__ > 2
extern "C" {
#if !defined(DO_TAOCRYPT_KERNEL_MODE)
#include <assert.h>
#else
#include "kernelc.hpp"
#endif
/* Disallow inline __cxa_pure_virtual() */
static int __cxa_pure_virtual() __attribute__((noinline, used));

View File

@ -42,6 +42,7 @@ public:
word32 getDigestSize() const { return DIGEST_SIZE; }
word32 getPadSize() const { return PAD_SIZE; }
void Update(const byte* data, word32 len);
void Init();
SHA(const SHA&);
@ -50,6 +51,7 @@ public:
void Swap(SHA&);
private:
void Transform();
void AsmTransform(const byte* data, word32 times);
};

View File

@ -0,0 +1,86 @@
/* twofish.hpp
*
* Copyright (C) 2003 Sawtooth Consulting Ltd.
*
* This file is part of yaSSL.
*
* yaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* yaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/* twofish.hpp defines Twofish
*/
#ifndef TAO_CRYPT_TWOFISH_HPP
#define TAO_CRYPT_TWOFISH_HPP
#include "misc.hpp"
#include "modes.hpp"
#include "algorithm.hpp"
namespace TaoCrypt {
enum { TWOFISH_BLOCK_SIZE = 16 };
// Twofish encryption and decryption, see
class Twofish : public Mode_BASE {
public:
enum { BLOCK_SIZE = TWOFISH_BLOCK_SIZE };
Twofish(CipherDir DIR, Mode MODE)
: Mode_BASE(BLOCK_SIZE), dir_(DIR), mode_(MODE) {}
void Process(byte*, const byte*, word32);
void SetKey(const byte* key, word32 sz, CipherDir fake = ENCRYPTION);
void SetIV(const byte* iv) { memcpy(r_, iv, BLOCK_SIZE); }
private:
CipherDir dir_;
Mode mode_;
static const byte q_[2][256];
static const word32 mds_[4][256];
word32 k_[40];
word32 s_[4][256];
static word32 h0(word32 x, const word32 *key, unsigned int kLen);
static word32 h(word32 x, const word32 *key, unsigned int kLen);
void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
void encrypt(const byte*, const byte*, byte*) const;
void decrypt(const byte*, const byte*, byte*) const;
void AsmEncrypt(const byte* inBlock, byte* outBlock) const;
void AsmDecrypt(const byte* inBlock, byte* outBlock) const;
Twofish(const Twofish&); // hide copy
Twofish& operator=(const Twofish&); // and assign
};
typedef BlockCipher<ENCRYPTION, Twofish, ECB> Twofish_ECB_Encryption;
typedef BlockCipher<DECRYPTION, Twofish, ECB> Twofish_ECB_Decryption;
typedef BlockCipher<ENCRYPTION, Twofish, CBC> Twofish_CBC_Encryption;
typedef BlockCipher<DECRYPTION, Twofish, CBC> Twofish_CBC_Decryption;
} // naemspace
#endif // TAO_CRYPT_TWOFISH_HPP

View File

@ -66,6 +66,7 @@ typedef unsigned int word32;
#endif
#endif
#if defined(HAVE_64_MULTIPLY) && (defined(__alpha__) || defined(__ia64__) \
|| defined(_ARCH_PPC64) || defined(__mips64) || defined(__x86_64__))
// These platforms have 64-bit CPU registers. Unfortunately most C++ compilers

View File

@ -2,10 +2,12 @@ INCLUDES = -I../include -I../../mySTL
noinst_LTLIBRARIES = libtaocrypt.la
libtaocrypt_la_SOURCES = aes.cpp aestables.cpp algebra.cpp arc4.cpp asn.cpp \
coding.cpp dh.cpp des.cpp dsa.cpp file.cpp hash.cpp \
md2.cpp md5.cpp misc.cpp random.cpp ripemd.cpp rsa.cpp sha.cpp \
template_instnt.cpp integer.cpp
libtaocrypt_la_SOURCES = aes.cpp aestables.cpp algebra.cpp arc4.cpp \
asn.cpp bftables.cpp blowfish.cpp coding.cpp des.cpp dh.cpp \
dsa.cpp file.cpp hash.cpp integer.cpp md2.cpp md5.cpp misc.cpp \
random.cpp ripemd.cpp rsa.cpp sha.cpp template_instnt.cpp \
tftables.cpp twofish.cpp
libtaocrypt_la_CXXFLAGS = @yassl_taocrypt_extra_cxxflags@ -DYASSL_PURE_C
EXTRA_DIST = $(wildcard ../include/*.hpp)

File diff suppressed because it is too large Load Diff

View File

@ -28,689 +28,6 @@
namespace TaoCrypt {
/*
Te0[x] = S [x].[02, 01, 01, 03];
Te1[x] = S [x].[03, 02, 01, 01];
Te2[x] = S [x].[01, 03, 02, 01];
Te3[x] = S [x].[01, 01, 03, 02];
Te4[x] = S [x].[01, 01, 01, 01];
Td0[x] = Si[x].[0e, 09, 0d, 0b];
Td1[x] = Si[x].[0b, 0e, 09, 0d];
Td2[x] = Si[x].[0d, 0b, 0e, 09];
Td3[x] = Si[x].[09, 0d, 0b, 0e];
Td4[x] = Si[x].[01, 01, 01, 01];
*/
const word32 AES::Te0[256] = {
0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU,
0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U,
0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU,
0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU,
0x8fcaca45U, 0x1f82829dU, 0x89c9c940U, 0xfa7d7d87U,
0xeffafa15U, 0xb25959ebU, 0x8e4747c9U, 0xfbf0f00bU,
0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, 0x45afafeaU,
0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU,
0x75b7b7c2U, 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU,
0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU,
0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U,
0xe2717193U, 0xabd8d873U, 0x62313153U, 0x2a15153fU,
0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU,
0x30181828U, 0x379696a1U, 0x0a05050fU, 0x2f9a9ab5U,
0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU,
0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, 0xea75759fU,
0x1209091bU, 0x1d83839eU, 0x582c2c74U, 0x341a1a2eU,
0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU,
0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU,
0x5229297bU, 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U,
0xa65353f5U, 0xb9d1d168U, 0x00000000U, 0xc1eded2cU,
0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU,
0xd46a6abeU, 0x8dcbcb46U, 0x67bebed9U, 0x7239394bU,
0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU,
0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, 0xedfbfb16U,
0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U,
0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U,
0xa05050f0U, 0x783c3c44U, 0x259f9fbaU, 0x4ba8a8e3U,
0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU,
0x3f9292adU, 0x219d9dbcU, 0x70383848U, 0xf1f5f504U,
0x63bcbcdfU, 0x77b6b6c1U, 0xafdada75U, 0x42212163U,
0x20101030U, 0xe5ffff1aU, 0xfdf3f30eU, 0xbfd2d26dU,
0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU,
0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, 0x2e171739U,
0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U,
0xc86464acU, 0xba5d5de7U, 0x3219192bU, 0xe6737395U,
0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU,
0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U,
0x8c4646caU, 0xc7eeee29U, 0x6bb8b8d3U, 0x2814143cU,
0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U,
0xdbe0e03bU, 0x64323256U, 0x743a3a4eU, 0x140a0a1eU,
0x924949dbU, 0x0c06060aU, 0x4824246cU, 0xb85c5ce4U,
0x9fc2c25dU, 0xbdd3d36eU, 0x43acacefU, 0xc46262a6U,
0x399191a8U, 0x319595a4U, 0xd3e4e437U, 0xf279798bU,
0xd5e7e732U, 0x8bc8c843U, 0x6e373759U, 0xda6d6db7U,
0x018d8d8cU, 0xb1d5d564U, 0x9c4e4ed2U, 0x49a9a9e0U,
0xd86c6cb4U, 0xac5656faU, 0xf3f4f407U, 0xcfeaea25U,
0xca6565afU, 0xf47a7a8eU, 0x47aeaee9U, 0x10080818U,
0x6fbabad5U, 0xf0787888U, 0x4a25256fU, 0x5c2e2e72U,
0x381c1c24U, 0x57a6a6f1U, 0x73b4b4c7U, 0x97c6c651U,
0xcbe8e823U, 0xa1dddd7cU, 0xe874749cU, 0x3e1f1f21U,
0x964b4bddU, 0x61bdbddcU, 0x0d8b8b86U, 0x0f8a8a85U,
0xe0707090U, 0x7c3e3e42U, 0x71b5b5c4U, 0xcc6666aaU,
0x904848d8U, 0x06030305U, 0xf7f6f601U, 0x1c0e0e12U,
0xc26161a3U, 0x6a35355fU, 0xae5757f9U, 0x69b9b9d0U,
0x17868691U, 0x99c1c158U, 0x3a1d1d27U, 0x279e9eb9U,
0xd9e1e138U, 0xebf8f813U, 0x2b9898b3U, 0x22111133U,
0xd26969bbU, 0xa9d9d970U, 0x078e8e89U, 0x339494a7U,
0x2d9b9bb6U, 0x3c1e1e22U, 0x15878792U, 0xc9e9e920U,
0x87cece49U, 0xaa5555ffU, 0x50282878U, 0xa5dfdf7aU,
0x038c8c8fU, 0x59a1a1f8U, 0x09898980U, 0x1a0d0d17U,
0x65bfbfdaU, 0xd7e6e631U, 0x844242c6U, 0xd06868b8U,
0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U,
0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU,
};
const word32 AES::Te1[256] = {
0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU,
0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U,
0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU,
0x19e7fefeU, 0x62b5d7d7U, 0xe64dababU, 0x9aec7676U,
0x458fcacaU, 0x9d1f8282U, 0x4089c9c9U, 0x87fa7d7dU,
0x15effafaU, 0xebb25959U, 0xc98e4747U, 0x0bfbf0f0U,
0xec41adadU, 0x67b3d4d4U, 0xfd5fa2a2U, 0xea45afafU,
0xbf239c9cU, 0xf753a4a4U, 0x96e47272U, 0x5b9bc0c0U,
0xc275b7b7U, 0x1ce1fdfdU, 0xae3d9393U, 0x6a4c2626U,
0x5a6c3636U, 0x417e3f3fU, 0x02f5f7f7U, 0x4f83ccccU,
0x5c683434U, 0xf451a5a5U, 0x34d1e5e5U, 0x08f9f1f1U,
0x93e27171U, 0x73abd8d8U, 0x53623131U, 0x3f2a1515U,
0x0c080404U, 0x5295c7c7U, 0x65462323U, 0x5e9dc3c3U,
0x28301818U, 0xa1379696U, 0x0f0a0505U, 0xb52f9a9aU,
0x090e0707U, 0x36241212U, 0x9b1b8080U, 0x3ddfe2e2U,
0x26cdebebU, 0x694e2727U, 0xcd7fb2b2U, 0x9fea7575U,
0x1b120909U, 0x9e1d8383U, 0x74582c2cU, 0x2e341a1aU,
0x2d361b1bU, 0xb2dc6e6eU, 0xeeb45a5aU, 0xfb5ba0a0U,
0xf6a45252U, 0x4d763b3bU, 0x61b7d6d6U, 0xce7db3b3U,
0x7b522929U, 0x3edde3e3U, 0x715e2f2fU, 0x97138484U,
0xf5a65353U, 0x68b9d1d1U, 0x00000000U, 0x2cc1ededU,
0x60402020U, 0x1fe3fcfcU, 0xc879b1b1U, 0xedb65b5bU,
0xbed46a6aU, 0x468dcbcbU, 0xd967bebeU, 0x4b723939U,
0xde944a4aU, 0xd4984c4cU, 0xe8b05858U, 0x4a85cfcfU,
0x6bbbd0d0U, 0x2ac5efefU, 0xe54faaaaU, 0x16edfbfbU,
0xc5864343U, 0xd79a4d4dU, 0x55663333U, 0x94118585U,
0xcf8a4545U, 0x10e9f9f9U, 0x06040202U, 0x81fe7f7fU,
0xf0a05050U, 0x44783c3cU, 0xba259f9fU, 0xe34ba8a8U,
0xf3a25151U, 0xfe5da3a3U, 0xc0804040U, 0x8a058f8fU,
0xad3f9292U, 0xbc219d9dU, 0x48703838U, 0x04f1f5f5U,
0xdf63bcbcU, 0xc177b6b6U, 0x75afdadaU, 0x63422121U,
0x30201010U, 0x1ae5ffffU, 0x0efdf3f3U, 0x6dbfd2d2U,
0x4c81cdcdU, 0x14180c0cU, 0x35261313U, 0x2fc3ececU,
0xe1be5f5fU, 0xa2359797U, 0xcc884444U, 0x392e1717U,
0x5793c4c4U, 0xf255a7a7U, 0x82fc7e7eU, 0x477a3d3dU,
0xacc86464U, 0xe7ba5d5dU, 0x2b321919U, 0x95e67373U,
0xa0c06060U, 0x98198181U, 0xd19e4f4fU, 0x7fa3dcdcU,
0x66442222U, 0x7e542a2aU, 0xab3b9090U, 0x830b8888U,
0xca8c4646U, 0x29c7eeeeU, 0xd36bb8b8U, 0x3c281414U,
0x79a7dedeU, 0xe2bc5e5eU, 0x1d160b0bU, 0x76addbdbU,
0x3bdbe0e0U, 0x56643232U, 0x4e743a3aU, 0x1e140a0aU,
0xdb924949U, 0x0a0c0606U, 0x6c482424U, 0xe4b85c5cU,
0x5d9fc2c2U, 0x6ebdd3d3U, 0xef43acacU, 0xa6c46262U,
0xa8399191U, 0xa4319595U, 0x37d3e4e4U, 0x8bf27979U,
0x32d5e7e7U, 0x438bc8c8U, 0x596e3737U, 0xb7da6d6dU,
0x8c018d8dU, 0x64b1d5d5U, 0xd29c4e4eU, 0xe049a9a9U,
0xb4d86c6cU, 0xfaac5656U, 0x07f3f4f4U, 0x25cfeaeaU,
0xafca6565U, 0x8ef47a7aU, 0xe947aeaeU, 0x18100808U,
0xd56fbabaU, 0x88f07878U, 0x6f4a2525U, 0x725c2e2eU,
0x24381c1cU, 0xf157a6a6U, 0xc773b4b4U, 0x5197c6c6U,
0x23cbe8e8U, 0x7ca1ddddU, 0x9ce87474U, 0x213e1f1fU,
0xdd964b4bU, 0xdc61bdbdU, 0x860d8b8bU, 0x850f8a8aU,
0x90e07070U, 0x427c3e3eU, 0xc471b5b5U, 0xaacc6666U,
0xd8904848U, 0x05060303U, 0x01f7f6f6U, 0x121c0e0eU,
0xa3c26161U, 0x5f6a3535U, 0xf9ae5757U, 0xd069b9b9U,
0x91178686U, 0x5899c1c1U, 0x273a1d1dU, 0xb9279e9eU,
0x38d9e1e1U, 0x13ebf8f8U, 0xb32b9898U, 0x33221111U,
0xbbd26969U, 0x70a9d9d9U, 0x89078e8eU, 0xa7339494U,
0xb62d9b9bU, 0x223c1e1eU, 0x92158787U, 0x20c9e9e9U,
0x4987ceceU, 0xffaa5555U, 0x78502828U, 0x7aa5dfdfU,
0x8f038c8cU, 0xf859a1a1U, 0x80098989U, 0x171a0d0dU,
0xda65bfbfU, 0x31d7e6e6U, 0xc6844242U, 0xb8d06868U,
0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU,
0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U,
};
const word32 AES::Te2[256] = {
0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU,
0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U,
0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU,
0xfe19e7feU, 0xd762b5d7U, 0xabe64dabU, 0x769aec76U,
0xca458fcaU, 0x829d1f82U, 0xc94089c9U, 0x7d87fa7dU,
0xfa15effaU, 0x59ebb259U, 0x47c98e47U, 0xf00bfbf0U,
0xadec41adU, 0xd467b3d4U, 0xa2fd5fa2U, 0xafea45afU,
0x9cbf239cU, 0xa4f753a4U, 0x7296e472U, 0xc05b9bc0U,
0xb7c275b7U, 0xfd1ce1fdU, 0x93ae3d93U, 0x266a4c26U,
0x365a6c36U, 0x3f417e3fU, 0xf702f5f7U, 0xcc4f83ccU,
0x345c6834U, 0xa5f451a5U, 0xe534d1e5U, 0xf108f9f1U,
0x7193e271U, 0xd873abd8U, 0x31536231U, 0x153f2a15U,
0x040c0804U, 0xc75295c7U, 0x23654623U, 0xc35e9dc3U,
0x18283018U, 0x96a13796U, 0x050f0a05U, 0x9ab52f9aU,
0x07090e07U, 0x12362412U, 0x809b1b80U, 0xe23ddfe2U,
0xeb26cdebU, 0x27694e27U, 0xb2cd7fb2U, 0x759fea75U,
0x091b1209U, 0x839e1d83U, 0x2c74582cU, 0x1a2e341aU,
0x1b2d361bU, 0x6eb2dc6eU, 0x5aeeb45aU, 0xa0fb5ba0U,
0x52f6a452U, 0x3b4d763bU, 0xd661b7d6U, 0xb3ce7db3U,
0x297b5229U, 0xe33edde3U, 0x2f715e2fU, 0x84971384U,
0x53f5a653U, 0xd168b9d1U, 0x00000000U, 0xed2cc1edU,
0x20604020U, 0xfc1fe3fcU, 0xb1c879b1U, 0x5bedb65bU,
0x6abed46aU, 0xcb468dcbU, 0xbed967beU, 0x394b7239U,
0x4ade944aU, 0x4cd4984cU, 0x58e8b058U, 0xcf4a85cfU,
0xd06bbbd0U, 0xef2ac5efU, 0xaae54faaU, 0xfb16edfbU,
0x43c58643U, 0x4dd79a4dU, 0x33556633U, 0x85941185U,
0x45cf8a45U, 0xf910e9f9U, 0x02060402U, 0x7f81fe7fU,
0x50f0a050U, 0x3c44783cU, 0x9fba259fU, 0xa8e34ba8U,
0x51f3a251U, 0xa3fe5da3U, 0x40c08040U, 0x8f8a058fU,
0x92ad3f92U, 0x9dbc219dU, 0x38487038U, 0xf504f1f5U,
0xbcdf63bcU, 0xb6c177b6U, 0xda75afdaU, 0x21634221U,
0x10302010U, 0xff1ae5ffU, 0xf30efdf3U, 0xd26dbfd2U,
0xcd4c81cdU, 0x0c14180cU, 0x13352613U, 0xec2fc3ecU,
0x5fe1be5fU, 0x97a23597U, 0x44cc8844U, 0x17392e17U,
0xc45793c4U, 0xa7f255a7U, 0x7e82fc7eU, 0x3d477a3dU,
0x64acc864U, 0x5de7ba5dU, 0x192b3219U, 0x7395e673U,
0x60a0c060U, 0x81981981U, 0x4fd19e4fU, 0xdc7fa3dcU,
0x22664422U, 0x2a7e542aU, 0x90ab3b90U, 0x88830b88U,
0x46ca8c46U, 0xee29c7eeU, 0xb8d36bb8U, 0x143c2814U,
0xde79a7deU, 0x5ee2bc5eU, 0x0b1d160bU, 0xdb76addbU,
0xe03bdbe0U, 0x32566432U, 0x3a4e743aU, 0x0a1e140aU,
0x49db9249U, 0x060a0c06U, 0x246c4824U, 0x5ce4b85cU,
0xc25d9fc2U, 0xd36ebdd3U, 0xacef43acU, 0x62a6c462U,
0x91a83991U, 0x95a43195U, 0xe437d3e4U, 0x798bf279U,
0xe732d5e7U, 0xc8438bc8U, 0x37596e37U, 0x6db7da6dU,
0x8d8c018dU, 0xd564b1d5U, 0x4ed29c4eU, 0xa9e049a9U,
0x6cb4d86cU, 0x56faac56U, 0xf407f3f4U, 0xea25cfeaU,
0x65afca65U, 0x7a8ef47aU, 0xaee947aeU, 0x08181008U,
0xbad56fbaU, 0x7888f078U, 0x256f4a25U, 0x2e725c2eU,
0x1c24381cU, 0xa6f157a6U, 0xb4c773b4U, 0xc65197c6U,
0xe823cbe8U, 0xdd7ca1ddU, 0x749ce874U, 0x1f213e1fU,
0x4bdd964bU, 0xbddc61bdU, 0x8b860d8bU, 0x8a850f8aU,
0x7090e070U, 0x3e427c3eU, 0xb5c471b5U, 0x66aacc66U,
0x48d89048U, 0x03050603U, 0xf601f7f6U, 0x0e121c0eU,
0x61a3c261U, 0x355f6a35U, 0x57f9ae57U, 0xb9d069b9U,
0x86911786U, 0xc15899c1U, 0x1d273a1dU, 0x9eb9279eU,
0xe138d9e1U, 0xf813ebf8U, 0x98b32b98U, 0x11332211U,
0x69bbd269U, 0xd970a9d9U, 0x8e89078eU, 0x94a73394U,
0x9bb62d9bU, 0x1e223c1eU, 0x87921587U, 0xe920c9e9U,
0xce4987ceU, 0x55ffaa55U, 0x28785028U, 0xdf7aa5dfU,
0x8c8f038cU, 0xa1f859a1U, 0x89800989U, 0x0d171a0dU,
0xbfda65bfU, 0xe631d7e6U, 0x42c68442U, 0x68b8d068U,
0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU,
0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U,
};
const word32 AES::Te3[256] = {
0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U,
0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U,
0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U,
0xfefe19e7U, 0xd7d762b5U, 0xababe64dU, 0x76769aecU,
0xcaca458fU, 0x82829d1fU, 0xc9c94089U, 0x7d7d87faU,
0xfafa15efU, 0x5959ebb2U, 0x4747c98eU, 0xf0f00bfbU,
0xadadec41U, 0xd4d467b3U, 0xa2a2fd5fU, 0xafafea45U,
0x9c9cbf23U, 0xa4a4f753U, 0x727296e4U, 0xc0c05b9bU,
0xb7b7c275U, 0xfdfd1ce1U, 0x9393ae3dU, 0x26266a4cU,
0x36365a6cU, 0x3f3f417eU, 0xf7f702f5U, 0xcccc4f83U,
0x34345c68U, 0xa5a5f451U, 0xe5e534d1U, 0xf1f108f9U,
0x717193e2U, 0xd8d873abU, 0x31315362U, 0x15153f2aU,
0x04040c08U, 0xc7c75295U, 0x23236546U, 0xc3c35e9dU,
0x18182830U, 0x9696a137U, 0x05050f0aU, 0x9a9ab52fU,
0x0707090eU, 0x12123624U, 0x80809b1bU, 0xe2e23ddfU,
0xebeb26cdU, 0x2727694eU, 0xb2b2cd7fU, 0x75759feaU,
0x09091b12U, 0x83839e1dU, 0x2c2c7458U, 0x1a1a2e34U,
0x1b1b2d36U, 0x6e6eb2dcU, 0x5a5aeeb4U, 0xa0a0fb5bU,
0x5252f6a4U, 0x3b3b4d76U, 0xd6d661b7U, 0xb3b3ce7dU,
0x29297b52U, 0xe3e33eddU, 0x2f2f715eU, 0x84849713U,
0x5353f5a6U, 0xd1d168b9U, 0x00000000U, 0xeded2cc1U,
0x20206040U, 0xfcfc1fe3U, 0xb1b1c879U, 0x5b5bedb6U,
0x6a6abed4U, 0xcbcb468dU, 0xbebed967U, 0x39394b72U,
0x4a4ade94U, 0x4c4cd498U, 0x5858e8b0U, 0xcfcf4a85U,
0xd0d06bbbU, 0xefef2ac5U, 0xaaaae54fU, 0xfbfb16edU,
0x4343c586U, 0x4d4dd79aU, 0x33335566U, 0x85859411U,
0x4545cf8aU, 0xf9f910e9U, 0x02020604U, 0x7f7f81feU,
0x5050f0a0U, 0x3c3c4478U, 0x9f9fba25U, 0xa8a8e34bU,
0x5151f3a2U, 0xa3a3fe5dU, 0x4040c080U, 0x8f8f8a05U,
0x9292ad3fU, 0x9d9dbc21U, 0x38384870U, 0xf5f504f1U,
0xbcbcdf63U, 0xb6b6c177U, 0xdada75afU, 0x21216342U,
0x10103020U, 0xffff1ae5U, 0xf3f30efdU, 0xd2d26dbfU,
0xcdcd4c81U, 0x0c0c1418U, 0x13133526U, 0xecec2fc3U,
0x5f5fe1beU, 0x9797a235U, 0x4444cc88U, 0x1717392eU,
0xc4c45793U, 0xa7a7f255U, 0x7e7e82fcU, 0x3d3d477aU,
0x6464acc8U, 0x5d5de7baU, 0x19192b32U, 0x737395e6U,
0x6060a0c0U, 0x81819819U, 0x4f4fd19eU, 0xdcdc7fa3U,
0x22226644U, 0x2a2a7e54U, 0x9090ab3bU, 0x8888830bU,
0x4646ca8cU, 0xeeee29c7U, 0xb8b8d36bU, 0x14143c28U,
0xdede79a7U, 0x5e5ee2bcU, 0x0b0b1d16U, 0xdbdb76adU,
0xe0e03bdbU, 0x32325664U, 0x3a3a4e74U, 0x0a0a1e14U,
0x4949db92U, 0x06060a0cU, 0x24246c48U, 0x5c5ce4b8U,
0xc2c25d9fU, 0xd3d36ebdU, 0xacacef43U, 0x6262a6c4U,
0x9191a839U, 0x9595a431U, 0xe4e437d3U, 0x79798bf2U,
0xe7e732d5U, 0xc8c8438bU, 0x3737596eU, 0x6d6db7daU,
0x8d8d8c01U, 0xd5d564b1U, 0x4e4ed29cU, 0xa9a9e049U,
0x6c6cb4d8U, 0x5656faacU, 0xf4f407f3U, 0xeaea25cfU,
0x6565afcaU, 0x7a7a8ef4U, 0xaeaee947U, 0x08081810U,
0xbabad56fU, 0x787888f0U, 0x25256f4aU, 0x2e2e725cU,
0x1c1c2438U, 0xa6a6f157U, 0xb4b4c773U, 0xc6c65197U,
0xe8e823cbU, 0xdddd7ca1U, 0x74749ce8U, 0x1f1f213eU,
0x4b4bdd96U, 0xbdbddc61U, 0x8b8b860dU, 0x8a8a850fU,
0x707090e0U, 0x3e3e427cU, 0xb5b5c471U, 0x6666aaccU,
0x4848d890U, 0x03030506U, 0xf6f601f7U, 0x0e0e121cU,
0x6161a3c2U, 0x35355f6aU, 0x5757f9aeU, 0xb9b9d069U,
0x86869117U, 0xc1c15899U, 0x1d1d273aU, 0x9e9eb927U,
0xe1e138d9U, 0xf8f813ebU, 0x9898b32bU, 0x11113322U,
0x6969bbd2U, 0xd9d970a9U, 0x8e8e8907U, 0x9494a733U,
0x9b9bb62dU, 0x1e1e223cU, 0x87879215U, 0xe9e920c9U,
0xcece4987U, 0x5555ffaaU, 0x28287850U, 0xdfdf7aa5U,
0x8c8c8f03U, 0xa1a1f859U, 0x89898009U, 0x0d0d171aU,
0xbfbfda65U, 0xe6e631d7U, 0x4242c684U, 0x6868b8d0U,
0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU,
0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU,
};
const word32 AES::Te4[256] = {
0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU,
0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U,
0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU,
0xfefefefeU, 0xd7d7d7d7U, 0xababababU, 0x76767676U,
0xcacacacaU, 0x82828282U, 0xc9c9c9c9U, 0x7d7d7d7dU,
0xfafafafaU, 0x59595959U, 0x47474747U, 0xf0f0f0f0U,
0xadadadadU, 0xd4d4d4d4U, 0xa2a2a2a2U, 0xafafafafU,
0x9c9c9c9cU, 0xa4a4a4a4U, 0x72727272U, 0xc0c0c0c0U,
0xb7b7b7b7U, 0xfdfdfdfdU, 0x93939393U, 0x26262626U,
0x36363636U, 0x3f3f3f3fU, 0xf7f7f7f7U, 0xccccccccU,
0x34343434U, 0xa5a5a5a5U, 0xe5e5e5e5U, 0xf1f1f1f1U,
0x71717171U, 0xd8d8d8d8U, 0x31313131U, 0x15151515U,
0x04040404U, 0xc7c7c7c7U, 0x23232323U, 0xc3c3c3c3U,
0x18181818U, 0x96969696U, 0x05050505U, 0x9a9a9a9aU,
0x07070707U, 0x12121212U, 0x80808080U, 0xe2e2e2e2U,
0xebebebebU, 0x27272727U, 0xb2b2b2b2U, 0x75757575U,
0x09090909U, 0x83838383U, 0x2c2c2c2cU, 0x1a1a1a1aU,
0x1b1b1b1bU, 0x6e6e6e6eU, 0x5a5a5a5aU, 0xa0a0a0a0U,
0x52525252U, 0x3b3b3b3bU, 0xd6d6d6d6U, 0xb3b3b3b3U,
0x29292929U, 0xe3e3e3e3U, 0x2f2f2f2fU, 0x84848484U,
0x53535353U, 0xd1d1d1d1U, 0x00000000U, 0xededededU,
0x20202020U, 0xfcfcfcfcU, 0xb1b1b1b1U, 0x5b5b5b5bU,
0x6a6a6a6aU, 0xcbcbcbcbU, 0xbebebebeU, 0x39393939U,
0x4a4a4a4aU, 0x4c4c4c4cU, 0x58585858U, 0xcfcfcfcfU,
0xd0d0d0d0U, 0xefefefefU, 0xaaaaaaaaU, 0xfbfbfbfbU,
0x43434343U, 0x4d4d4d4dU, 0x33333333U, 0x85858585U,
0x45454545U, 0xf9f9f9f9U, 0x02020202U, 0x7f7f7f7fU,
0x50505050U, 0x3c3c3c3cU, 0x9f9f9f9fU, 0xa8a8a8a8U,
0x51515151U, 0xa3a3a3a3U, 0x40404040U, 0x8f8f8f8fU,
0x92929292U, 0x9d9d9d9dU, 0x38383838U, 0xf5f5f5f5U,
0xbcbcbcbcU, 0xb6b6b6b6U, 0xdadadadaU, 0x21212121U,
0x10101010U, 0xffffffffU, 0xf3f3f3f3U, 0xd2d2d2d2U,
0xcdcdcdcdU, 0x0c0c0c0cU, 0x13131313U, 0xececececU,
0x5f5f5f5fU, 0x97979797U, 0x44444444U, 0x17171717U,
0xc4c4c4c4U, 0xa7a7a7a7U, 0x7e7e7e7eU, 0x3d3d3d3dU,
0x64646464U, 0x5d5d5d5dU, 0x19191919U, 0x73737373U,
0x60606060U, 0x81818181U, 0x4f4f4f4fU, 0xdcdcdcdcU,
0x22222222U, 0x2a2a2a2aU, 0x90909090U, 0x88888888U,
0x46464646U, 0xeeeeeeeeU, 0xb8b8b8b8U, 0x14141414U,
0xdedededeU, 0x5e5e5e5eU, 0x0b0b0b0bU, 0xdbdbdbdbU,
0xe0e0e0e0U, 0x32323232U, 0x3a3a3a3aU, 0x0a0a0a0aU,
0x49494949U, 0x06060606U, 0x24242424U, 0x5c5c5c5cU,
0xc2c2c2c2U, 0xd3d3d3d3U, 0xacacacacU, 0x62626262U,
0x91919191U, 0x95959595U, 0xe4e4e4e4U, 0x79797979U,
0xe7e7e7e7U, 0xc8c8c8c8U, 0x37373737U, 0x6d6d6d6dU,
0x8d8d8d8dU, 0xd5d5d5d5U, 0x4e4e4e4eU, 0xa9a9a9a9U,
0x6c6c6c6cU, 0x56565656U, 0xf4f4f4f4U, 0xeaeaeaeaU,
0x65656565U, 0x7a7a7a7aU, 0xaeaeaeaeU, 0x08080808U,
0xbabababaU, 0x78787878U, 0x25252525U, 0x2e2e2e2eU,
0x1c1c1c1cU, 0xa6a6a6a6U, 0xb4b4b4b4U, 0xc6c6c6c6U,
0xe8e8e8e8U, 0xddddddddU, 0x74747474U, 0x1f1f1f1fU,
0x4b4b4b4bU, 0xbdbdbdbdU, 0x8b8b8b8bU, 0x8a8a8a8aU,
0x70707070U, 0x3e3e3e3eU, 0xb5b5b5b5U, 0x66666666U,
0x48484848U, 0x03030303U, 0xf6f6f6f6U, 0x0e0e0e0eU,
0x61616161U, 0x35353535U, 0x57575757U, 0xb9b9b9b9U,
0x86868686U, 0xc1c1c1c1U, 0x1d1d1d1dU, 0x9e9e9e9eU,
0xe1e1e1e1U, 0xf8f8f8f8U, 0x98989898U, 0x11111111U,
0x69696969U, 0xd9d9d9d9U, 0x8e8e8e8eU, 0x94949494U,
0x9b9b9b9bU, 0x1e1e1e1eU, 0x87878787U, 0xe9e9e9e9U,
0xcecececeU, 0x55555555U, 0x28282828U, 0xdfdfdfdfU,
0x8c8c8c8cU, 0xa1a1a1a1U, 0x89898989U, 0x0d0d0d0dU,
0xbfbfbfbfU, 0xe6e6e6e6U, 0x42424242U, 0x68686868U,
0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU,
0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U,
};
const word32 AES::Td0[256] = {
0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U,
0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U,
0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U,
0x4fe5d7fcU, 0xc52acbd7U, 0x26354480U, 0xb562a38fU,
0xdeb15a49U, 0x25ba1b67U, 0x45ea0e98U, 0x5dfec0e1U,
0xc32f7502U, 0x814cf012U, 0x8d4697a3U, 0x6bd3f9c6U,
0x038f5fe7U, 0x15929c95U, 0xbf6d7aebU, 0x955259daU,
0xd4be832dU, 0x587421d3U, 0x49e06929U, 0x8ec9c844U,
0x75c2896aU, 0xf48e7978U, 0x99583e6bU, 0x27b971ddU,
0xbee14fb6U, 0xf088ad17U, 0xc920ac66U, 0x7dce3ab4U,
0x63df4a18U, 0xe51a3182U, 0x97513360U, 0x62537f45U,
0xb16477e0U, 0xbb6bae84U, 0xfe81a01cU, 0xf9082b94U,
0x70486858U, 0x8f45fd19U, 0x94de6c87U, 0x527bf8b7U,
0xab73d323U, 0x724b02e2U, 0xe31f8f57U, 0x6655ab2aU,
0xb2eb2807U, 0x2fb5c203U, 0x86c57b9aU, 0xd33708a5U,
0x302887f2U, 0x23bfa5b2U, 0x02036abaU, 0xed16825cU,
0x8acf1c2bU, 0xa779b492U, 0xf307f2f0U, 0x4e69e2a1U,
0x65daf4cdU, 0x0605bed5U, 0xd134621fU, 0xc4a6fe8aU,
0x342e539dU, 0xa2f355a0U, 0x058ae132U, 0xa4f6eb75U,
0x0b83ec39U, 0x4060efaaU, 0x5e719f06U, 0xbd6e1051U,
0x3e218af9U, 0x96dd063dU, 0xdd3e05aeU, 0x4de6bd46U,
0x91548db5U, 0x71c45d05U, 0x0406d46fU, 0x605015ffU,
0x1998fb24U, 0xd6bde997U, 0x894043ccU, 0x67d99e77U,
0xb0e842bdU, 0x07898b88U, 0xe7195b38U, 0x79c8eedbU,
0xa17c0a47U, 0x7c420fe9U, 0xf8841ec9U, 0x00000000U,
0x09808683U, 0x322bed48U, 0x1e1170acU, 0x6c5a724eU,
0xfd0efffbU, 0x0f853856U, 0x3daed51eU, 0x362d3927U,
0x0a0fd964U, 0x685ca621U, 0x9b5b54d1U, 0x24362e3aU,
0x0c0a67b1U, 0x9357e70fU, 0xb4ee96d2U, 0x1b9b919eU,
0x80c0c54fU, 0x61dc20a2U, 0x5a774b69U, 0x1c121a16U,
0xe293ba0aU, 0xc0a02ae5U, 0x3c22e043U, 0x121b171dU,
0x0e090d0bU, 0xf28bc7adU, 0x2db6a8b9U, 0x141ea9c8U,
0x57f11985U, 0xaf75074cU, 0xee99ddbbU, 0xa37f60fdU,
0xf701269fU, 0x5c72f5bcU, 0x44663bc5U, 0x5bfb7e34U,
0x8b432976U, 0xcb23c6dcU, 0xb6edfc68U, 0xb8e4f163U,
0xd731dccaU, 0x42638510U, 0x13972240U, 0x84c61120U,
0x854a247dU, 0xd2bb3df8U, 0xaef93211U, 0xc729a16dU,
0x1d9e2f4bU, 0xdcb230f3U, 0x0d8652ecU, 0x77c1e3d0U,
0x2bb3166cU, 0xa970b999U, 0x119448faU, 0x47e96422U,
0xa8fc8cc4U, 0xa0f03f1aU, 0x567d2cd8U, 0x223390efU,
0x87494ec7U, 0xd938d1c1U, 0x8ccaa2feU, 0x98d40b36U,
0xa6f581cfU, 0xa57ade28U, 0xdab78e26U, 0x3fadbfa4U,
0x2c3a9de4U, 0x5078920dU, 0x6a5fcc9bU, 0x547e4662U,
0xf68d13c2U, 0x90d8b8e8U, 0x2e39f75eU, 0x82c3aff5U,
0x9f5d80beU, 0x69d0937cU, 0x6fd52da9U, 0xcf2512b3U,
0xc8ac993bU, 0x10187da7U, 0xe89c636eU, 0xdb3bbb7bU,
0xcd267809U, 0x6e5918f4U, 0xec9ab701U, 0x834f9aa8U,
0xe6956e65U, 0xaaffe67eU, 0x21bccf08U, 0xef15e8e6U,
0xbae79bd9U, 0x4a6f36ceU, 0xea9f09d4U, 0x29b07cd6U,
0x31a4b2afU, 0x2a3f2331U, 0xc6a59430U, 0x35a266c0U,
0x744ebc37U, 0xfc82caa6U, 0xe090d0b0U, 0x33a7d815U,
0xf104984aU, 0x41ecdaf7U, 0x7fcd500eU, 0x1791f62fU,
0x764dd68dU, 0x43efb04dU, 0xccaa4d54U, 0xe49604dfU,
0x9ed1b5e3U, 0x4c6a881bU, 0xc12c1fb8U, 0x4665517fU,
0x9d5eea04U, 0x018c355dU, 0xfa877473U, 0xfb0b412eU,
0xb3671d5aU, 0x92dbd252U, 0xe9105633U, 0x6dd64713U,
0x9ad7618cU, 0x37a10c7aU, 0x59f8148eU, 0xeb133c89U,
0xcea927eeU, 0xb761c935U, 0xe11ce5edU, 0x7a47b13cU,
0x9cd2df59U, 0x55f2733fU, 0x1814ce79U, 0x73c737bfU,
0x53f7cdeaU, 0x5ffdaa5bU, 0xdf3d6f14U, 0x7844db86U,
0xcaaff381U, 0xb968c43eU, 0x3824342cU, 0xc2a3405fU,
0x161dc372U, 0xbce2250cU, 0x283c498bU, 0xff0d9541U,
0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U,
0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U,
};
const word32 AES::Td1[256] = {
0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU,
0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U,
0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU,
0xfc4fe5d7U, 0xd7c52acbU, 0x80263544U, 0x8fb562a3U,
0x49deb15aU, 0x6725ba1bU, 0x9845ea0eU, 0xe15dfec0U,
0x02c32f75U, 0x12814cf0U, 0xa38d4697U, 0xc66bd3f9U,
0xe7038f5fU, 0x9515929cU, 0xebbf6d7aU, 0xda955259U,
0x2dd4be83U, 0xd3587421U, 0x2949e069U, 0x448ec9c8U,
0x6a75c289U, 0x78f48e79U, 0x6b99583eU, 0xdd27b971U,
0xb6bee14fU, 0x17f088adU, 0x66c920acU, 0xb47dce3aU,
0x1863df4aU, 0x82e51a31U, 0x60975133U, 0x4562537fU,
0xe0b16477U, 0x84bb6baeU, 0x1cfe81a0U, 0x94f9082bU,
0x58704868U, 0x198f45fdU, 0x8794de6cU, 0xb7527bf8U,
0x23ab73d3U, 0xe2724b02U, 0x57e31f8fU, 0x2a6655abU,
0x07b2eb28U, 0x032fb5c2U, 0x9a86c57bU, 0xa5d33708U,
0xf2302887U, 0xb223bfa5U, 0xba02036aU, 0x5ced1682U,
0x2b8acf1cU, 0x92a779b4U, 0xf0f307f2U, 0xa14e69e2U,
0xcd65daf4U, 0xd50605beU, 0x1fd13462U, 0x8ac4a6feU,
0x9d342e53U, 0xa0a2f355U, 0x32058ae1U, 0x75a4f6ebU,
0x390b83ecU, 0xaa4060efU, 0x065e719fU, 0x51bd6e10U,
0xf93e218aU, 0x3d96dd06U, 0xaedd3e05U, 0x464de6bdU,
0xb591548dU, 0x0571c45dU, 0x6f0406d4U, 0xff605015U,
0x241998fbU, 0x97d6bde9U, 0xcc894043U, 0x7767d99eU,
0xbdb0e842U, 0x8807898bU, 0x38e7195bU, 0xdb79c8eeU,
0x47a17c0aU, 0xe97c420fU, 0xc9f8841eU, 0x00000000U,
0x83098086U, 0x48322bedU, 0xac1e1170U, 0x4e6c5a72U,
0xfbfd0effU, 0x560f8538U, 0x1e3daed5U, 0x27362d39U,
0x640a0fd9U, 0x21685ca6U, 0xd19b5b54U, 0x3a24362eU,
0xb10c0a67U, 0x0f9357e7U, 0xd2b4ee96U, 0x9e1b9b91U,
0x4f80c0c5U, 0xa261dc20U, 0x695a774bU, 0x161c121aU,
0x0ae293baU, 0xe5c0a02aU, 0x433c22e0U, 0x1d121b17U,
0x0b0e090dU, 0xadf28bc7U, 0xb92db6a8U, 0xc8141ea9U,
0x8557f119U, 0x4caf7507U, 0xbbee99ddU, 0xfda37f60U,
0x9ff70126U, 0xbc5c72f5U, 0xc544663bU, 0x345bfb7eU,
0x768b4329U, 0xdccb23c6U, 0x68b6edfcU, 0x63b8e4f1U,
0xcad731dcU, 0x10426385U, 0x40139722U, 0x2084c611U,
0x7d854a24U, 0xf8d2bb3dU, 0x11aef932U, 0x6dc729a1U,
0x4b1d9e2fU, 0xf3dcb230U, 0xec0d8652U, 0xd077c1e3U,
0x6c2bb316U, 0x99a970b9U, 0xfa119448U, 0x2247e964U,
0xc4a8fc8cU, 0x1aa0f03fU, 0xd8567d2cU, 0xef223390U,
0xc787494eU, 0xc1d938d1U, 0xfe8ccaa2U, 0x3698d40bU,
0xcfa6f581U, 0x28a57adeU, 0x26dab78eU, 0xa43fadbfU,
0xe42c3a9dU, 0x0d507892U, 0x9b6a5fccU, 0x62547e46U,
0xc2f68d13U, 0xe890d8b8U, 0x5e2e39f7U, 0xf582c3afU,
0xbe9f5d80U, 0x7c69d093U, 0xa96fd52dU, 0xb3cf2512U,
0x3bc8ac99U, 0xa710187dU, 0x6ee89c63U, 0x7bdb3bbbU,
0x09cd2678U, 0xf46e5918U, 0x01ec9ab7U, 0xa8834f9aU,
0x65e6956eU, 0x7eaaffe6U, 0x0821bccfU, 0xe6ef15e8U,
0xd9bae79bU, 0xce4a6f36U, 0xd4ea9f09U, 0xd629b07cU,
0xaf31a4b2U, 0x312a3f23U, 0x30c6a594U, 0xc035a266U,
0x37744ebcU, 0xa6fc82caU, 0xb0e090d0U, 0x1533a7d8U,
0x4af10498U, 0xf741ecdaU, 0x0e7fcd50U, 0x2f1791f6U,
0x8d764dd6U, 0x4d43efb0U, 0x54ccaa4dU, 0xdfe49604U,
0xe39ed1b5U, 0x1b4c6a88U, 0xb8c12c1fU, 0x7f466551U,
0x049d5eeaU, 0x5d018c35U, 0x73fa8774U, 0x2efb0b41U,
0x5ab3671dU, 0x5292dbd2U, 0x33e91056U, 0x136dd647U,
0x8c9ad761U, 0x7a37a10cU, 0x8e59f814U, 0x89eb133cU,
0xeecea927U, 0x35b761c9U, 0xede11ce5U, 0x3c7a47b1U,
0x599cd2dfU, 0x3f55f273U, 0x791814ceU, 0xbf73c737U,
0xea53f7cdU, 0x5b5ffdaaU, 0x14df3d6fU, 0x867844dbU,
0x81caaff3U, 0x3eb968c4U, 0x2c382434U, 0x5fc2a340U,
0x72161dc3U, 0x0cbce225U, 0x8b283c49U, 0x41ff0d95U,
0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U,
0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U,
};
const word32 AES::Td2[256] = {
0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U,
0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U,
0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U,
0xd7fc4fe5U, 0xcbd7c52aU, 0x44802635U, 0xa38fb562U,
0x5a49deb1U, 0x1b6725baU, 0x0e9845eaU, 0xc0e15dfeU,
0x7502c32fU, 0xf012814cU, 0x97a38d46U, 0xf9c66bd3U,
0x5fe7038fU, 0x9c951592U, 0x7aebbf6dU, 0x59da9552U,
0x832dd4beU, 0x21d35874U, 0x692949e0U, 0xc8448ec9U,
0x896a75c2U, 0x7978f48eU, 0x3e6b9958U, 0x71dd27b9U,
0x4fb6bee1U, 0xad17f088U, 0xac66c920U, 0x3ab47dceU,
0x4a1863dfU, 0x3182e51aU, 0x33609751U, 0x7f456253U,
0x77e0b164U, 0xae84bb6bU, 0xa01cfe81U, 0x2b94f908U,
0x68587048U, 0xfd198f45U, 0x6c8794deU, 0xf8b7527bU,
0xd323ab73U, 0x02e2724bU, 0x8f57e31fU, 0xab2a6655U,
0x2807b2ebU, 0xc2032fb5U, 0x7b9a86c5U, 0x08a5d337U,
0x87f23028U, 0xa5b223bfU, 0x6aba0203U, 0x825ced16U,
0x1c2b8acfU, 0xb492a779U, 0xf2f0f307U, 0xe2a14e69U,
0xf4cd65daU, 0xbed50605U, 0x621fd134U, 0xfe8ac4a6U,
0x539d342eU, 0x55a0a2f3U, 0xe132058aU, 0xeb75a4f6U,
0xec390b83U, 0xefaa4060U, 0x9f065e71U, 0x1051bd6eU,
0x8af93e21U, 0x063d96ddU, 0x05aedd3eU, 0xbd464de6U,
0x8db59154U, 0x5d0571c4U, 0xd46f0406U, 0x15ff6050U,
0xfb241998U, 0xe997d6bdU, 0x43cc8940U, 0x9e7767d9U,
0x42bdb0e8U, 0x8b880789U, 0x5b38e719U, 0xeedb79c8U,
0x0a47a17cU, 0x0fe97c42U, 0x1ec9f884U, 0x00000000U,
0x86830980U, 0xed48322bU, 0x70ac1e11U, 0x724e6c5aU,
0xfffbfd0eU, 0x38560f85U, 0xd51e3daeU, 0x3927362dU,
0xd9640a0fU, 0xa621685cU, 0x54d19b5bU, 0x2e3a2436U,
0x67b10c0aU, 0xe70f9357U, 0x96d2b4eeU, 0x919e1b9bU,
0xc54f80c0U, 0x20a261dcU, 0x4b695a77U, 0x1a161c12U,
0xba0ae293U, 0x2ae5c0a0U, 0xe0433c22U, 0x171d121bU,
0x0d0b0e09U, 0xc7adf28bU, 0xa8b92db6U, 0xa9c8141eU,
0x198557f1U, 0x074caf75U, 0xddbbee99U, 0x60fda37fU,
0x269ff701U, 0xf5bc5c72U, 0x3bc54466U, 0x7e345bfbU,
0x29768b43U, 0xc6dccb23U, 0xfc68b6edU, 0xf163b8e4U,
0xdccad731U, 0x85104263U, 0x22401397U, 0x112084c6U,
0x247d854aU, 0x3df8d2bbU, 0x3211aef9U, 0xa16dc729U,
0x2f4b1d9eU, 0x30f3dcb2U, 0x52ec0d86U, 0xe3d077c1U,
0x166c2bb3U, 0xb999a970U, 0x48fa1194U, 0x642247e9U,
0x8cc4a8fcU, 0x3f1aa0f0U, 0x2cd8567dU, 0x90ef2233U,
0x4ec78749U, 0xd1c1d938U, 0xa2fe8ccaU, 0x0b3698d4U,
0x81cfa6f5U, 0xde28a57aU, 0x8e26dab7U, 0xbfa43fadU,
0x9de42c3aU, 0x920d5078U, 0xcc9b6a5fU, 0x4662547eU,
0x13c2f68dU, 0xb8e890d8U, 0xf75e2e39U, 0xaff582c3U,
0x80be9f5dU, 0x937c69d0U, 0x2da96fd5U, 0x12b3cf25U,
0x993bc8acU, 0x7da71018U, 0x636ee89cU, 0xbb7bdb3bU,
0x7809cd26U, 0x18f46e59U, 0xb701ec9aU, 0x9aa8834fU,
0x6e65e695U, 0xe67eaaffU, 0xcf0821bcU, 0xe8e6ef15U,
0x9bd9bae7U, 0x36ce4a6fU, 0x09d4ea9fU, 0x7cd629b0U,
0xb2af31a4U, 0x23312a3fU, 0x9430c6a5U, 0x66c035a2U,
0xbc37744eU, 0xcaa6fc82U, 0xd0b0e090U, 0xd81533a7U,
0x984af104U, 0xdaf741ecU, 0x500e7fcdU, 0xf62f1791U,
0xd68d764dU, 0xb04d43efU, 0x4d54ccaaU, 0x04dfe496U,
0xb5e39ed1U, 0x881b4c6aU, 0x1fb8c12cU, 0x517f4665U,
0xea049d5eU, 0x355d018cU, 0x7473fa87U, 0x412efb0bU,
0x1d5ab367U, 0xd25292dbU, 0x5633e910U, 0x47136dd6U,
0x618c9ad7U, 0x0c7a37a1U, 0x148e59f8U, 0x3c89eb13U,
0x27eecea9U, 0xc935b761U, 0xe5ede11cU, 0xb13c7a47U,
0xdf599cd2U, 0x733f55f2U, 0xce791814U, 0x37bf73c7U,
0xcdea53f7U, 0xaa5b5ffdU, 0x6f14df3dU, 0xdb867844U,
0xf381caafU, 0xc43eb968U, 0x342c3824U, 0x405fc2a3U,
0xc372161dU, 0x250cbce2U, 0x498b283cU, 0x9541ff0dU,
0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U,
0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U,
};
const word32 AES::Td3[256] = {
0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU,
0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU,
0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U,
0xe5d7fc4fU, 0x2acbd7c5U, 0x35448026U, 0x62a38fb5U,
0xb15a49deU, 0xba1b6725U, 0xea0e9845U, 0xfec0e15dU,
0x2f7502c3U, 0x4cf01281U, 0x4697a38dU, 0xd3f9c66bU,
0x8f5fe703U, 0x929c9515U, 0x6d7aebbfU, 0x5259da95U,
0xbe832dd4U, 0x7421d358U, 0xe0692949U, 0xc9c8448eU,
0xc2896a75U, 0x8e7978f4U, 0x583e6b99U, 0xb971dd27U,
0xe14fb6beU, 0x88ad17f0U, 0x20ac66c9U, 0xce3ab47dU,
0xdf4a1863U, 0x1a3182e5U, 0x51336097U, 0x537f4562U,
0x6477e0b1U, 0x6bae84bbU, 0x81a01cfeU, 0x082b94f9U,
0x48685870U, 0x45fd198fU, 0xde6c8794U, 0x7bf8b752U,
0x73d323abU, 0x4b02e272U, 0x1f8f57e3U, 0x55ab2a66U,
0xeb2807b2U, 0xb5c2032fU, 0xc57b9a86U, 0x3708a5d3U,
0x2887f230U, 0xbfa5b223U, 0x036aba02U, 0x16825cedU,
0xcf1c2b8aU, 0x79b492a7U, 0x07f2f0f3U, 0x69e2a14eU,
0xdaf4cd65U, 0x05bed506U, 0x34621fd1U, 0xa6fe8ac4U,
0x2e539d34U, 0xf355a0a2U, 0x8ae13205U, 0xf6eb75a4U,
0x83ec390bU, 0x60efaa40U, 0x719f065eU, 0x6e1051bdU,
0x218af93eU, 0xdd063d96U, 0x3e05aeddU, 0xe6bd464dU,
0x548db591U, 0xc45d0571U, 0x06d46f04U, 0x5015ff60U,
0x98fb2419U, 0xbde997d6U, 0x4043cc89U, 0xd99e7767U,
0xe842bdb0U, 0x898b8807U, 0x195b38e7U, 0xc8eedb79U,
0x7c0a47a1U, 0x420fe97cU, 0x841ec9f8U, 0x00000000U,
0x80868309U, 0x2bed4832U, 0x1170ac1eU, 0x5a724e6cU,
0x0efffbfdU, 0x8538560fU, 0xaed51e3dU, 0x2d392736U,
0x0fd9640aU, 0x5ca62168U, 0x5b54d19bU, 0x362e3a24U,
0x0a67b10cU, 0x57e70f93U, 0xee96d2b4U, 0x9b919e1bU,
0xc0c54f80U, 0xdc20a261U, 0x774b695aU, 0x121a161cU,
0x93ba0ae2U, 0xa02ae5c0U, 0x22e0433cU, 0x1b171d12U,
0x090d0b0eU, 0x8bc7adf2U, 0xb6a8b92dU, 0x1ea9c814U,
0xf1198557U, 0x75074cafU, 0x99ddbbeeU, 0x7f60fda3U,
0x01269ff7U, 0x72f5bc5cU, 0x663bc544U, 0xfb7e345bU,
0x4329768bU, 0x23c6dccbU, 0xedfc68b6U, 0xe4f163b8U,
0x31dccad7U, 0x63851042U, 0x97224013U, 0xc6112084U,
0x4a247d85U, 0xbb3df8d2U, 0xf93211aeU, 0x29a16dc7U,
0x9e2f4b1dU, 0xb230f3dcU, 0x8652ec0dU, 0xc1e3d077U,
0xb3166c2bU, 0x70b999a9U, 0x9448fa11U, 0xe9642247U,
0xfc8cc4a8U, 0xf03f1aa0U, 0x7d2cd856U, 0x3390ef22U,
0x494ec787U, 0x38d1c1d9U, 0xcaa2fe8cU, 0xd40b3698U,
0xf581cfa6U, 0x7ade28a5U, 0xb78e26daU, 0xadbfa43fU,
0x3a9de42cU, 0x78920d50U, 0x5fcc9b6aU, 0x7e466254U,
0x8d13c2f6U, 0xd8b8e890U, 0x39f75e2eU, 0xc3aff582U,
0x5d80be9fU, 0xd0937c69U, 0xd52da96fU, 0x2512b3cfU,
0xac993bc8U, 0x187da710U, 0x9c636ee8U, 0x3bbb7bdbU,
0x267809cdU, 0x5918f46eU, 0x9ab701ecU, 0x4f9aa883U,
0x956e65e6U, 0xffe67eaaU, 0xbccf0821U, 0x15e8e6efU,
0xe79bd9baU, 0x6f36ce4aU, 0x9f09d4eaU, 0xb07cd629U,
0xa4b2af31U, 0x3f23312aU, 0xa59430c6U, 0xa266c035U,
0x4ebc3774U, 0x82caa6fcU, 0x90d0b0e0U, 0xa7d81533U,
0x04984af1U, 0xecdaf741U, 0xcd500e7fU, 0x91f62f17U,
0x4dd68d76U, 0xefb04d43U, 0xaa4d54ccU, 0x9604dfe4U,
0xd1b5e39eU, 0x6a881b4cU, 0x2c1fb8c1U, 0x65517f46U,
0x5eea049dU, 0x8c355d01U, 0x877473faU, 0x0b412efbU,
0x671d5ab3U, 0xdbd25292U, 0x105633e9U, 0xd647136dU,
0xd7618c9aU, 0xa10c7a37U, 0xf8148e59U, 0x133c89ebU,
0xa927eeceU, 0x61c935b7U, 0x1ce5ede1U, 0x47b13c7aU,
0xd2df599cU, 0xf2733f55U, 0x14ce7918U, 0xc737bf73U,
0xf7cdea53U, 0xfdaa5b5fU, 0x3d6f14dfU, 0x44db8678U,
0xaff381caU, 0x68c43eb9U, 0x24342c38U, 0xa3405fc2U,
0x1dc37216U, 0xe2250cbcU, 0x3c498b28U, 0x0d9541ffU,
0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U,
0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U,
};
const word32 AES::Td4[256] = {
0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U,
0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U,
0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU,
0x81818181U, 0xf3f3f3f3U, 0xd7d7d7d7U, 0xfbfbfbfbU,
0x7c7c7c7cU, 0xe3e3e3e3U, 0x39393939U, 0x82828282U,
0x9b9b9b9bU, 0x2f2f2f2fU, 0xffffffffU, 0x87878787U,
0x34343434U, 0x8e8e8e8eU, 0x43434343U, 0x44444444U,
0xc4c4c4c4U, 0xdedededeU, 0xe9e9e9e9U, 0xcbcbcbcbU,
0x54545454U, 0x7b7b7b7bU, 0x94949494U, 0x32323232U,
0xa6a6a6a6U, 0xc2c2c2c2U, 0x23232323U, 0x3d3d3d3dU,
0xeeeeeeeeU, 0x4c4c4c4cU, 0x95959595U, 0x0b0b0b0bU,
0x42424242U, 0xfafafafaU, 0xc3c3c3c3U, 0x4e4e4e4eU,
0x08080808U, 0x2e2e2e2eU, 0xa1a1a1a1U, 0x66666666U,
0x28282828U, 0xd9d9d9d9U, 0x24242424U, 0xb2b2b2b2U,
0x76767676U, 0x5b5b5b5bU, 0xa2a2a2a2U, 0x49494949U,
0x6d6d6d6dU, 0x8b8b8b8bU, 0xd1d1d1d1U, 0x25252525U,
0x72727272U, 0xf8f8f8f8U, 0xf6f6f6f6U, 0x64646464U,
0x86868686U, 0x68686868U, 0x98989898U, 0x16161616U,
0xd4d4d4d4U, 0xa4a4a4a4U, 0x5c5c5c5cU, 0xccccccccU,
0x5d5d5d5dU, 0x65656565U, 0xb6b6b6b6U, 0x92929292U,
0x6c6c6c6cU, 0x70707070U, 0x48484848U, 0x50505050U,
0xfdfdfdfdU, 0xededededU, 0xb9b9b9b9U, 0xdadadadaU,
0x5e5e5e5eU, 0x15151515U, 0x46464646U, 0x57575757U,
0xa7a7a7a7U, 0x8d8d8d8dU, 0x9d9d9d9dU, 0x84848484U,
0x90909090U, 0xd8d8d8d8U, 0xababababU, 0x00000000U,
0x8c8c8c8cU, 0xbcbcbcbcU, 0xd3d3d3d3U, 0x0a0a0a0aU,
0xf7f7f7f7U, 0xe4e4e4e4U, 0x58585858U, 0x05050505U,
0xb8b8b8b8U, 0xb3b3b3b3U, 0x45454545U, 0x06060606U,
0xd0d0d0d0U, 0x2c2c2c2cU, 0x1e1e1e1eU, 0x8f8f8f8fU,
0xcacacacaU, 0x3f3f3f3fU, 0x0f0f0f0fU, 0x02020202U,
0xc1c1c1c1U, 0xafafafafU, 0xbdbdbdbdU, 0x03030303U,
0x01010101U, 0x13131313U, 0x8a8a8a8aU, 0x6b6b6b6bU,
0x3a3a3a3aU, 0x91919191U, 0x11111111U, 0x41414141U,
0x4f4f4f4fU, 0x67676767U, 0xdcdcdcdcU, 0xeaeaeaeaU,
0x97979797U, 0xf2f2f2f2U, 0xcfcfcfcfU, 0xcecececeU,
0xf0f0f0f0U, 0xb4b4b4b4U, 0xe6e6e6e6U, 0x73737373U,
0x96969696U, 0xacacacacU, 0x74747474U, 0x22222222U,
0xe7e7e7e7U, 0xadadadadU, 0x35353535U, 0x85858585U,
0xe2e2e2e2U, 0xf9f9f9f9U, 0x37373737U, 0xe8e8e8e8U,
0x1c1c1c1cU, 0x75757575U, 0xdfdfdfdfU, 0x6e6e6e6eU,
0x47474747U, 0xf1f1f1f1U, 0x1a1a1a1aU, 0x71717171U,
0x1d1d1d1dU, 0x29292929U, 0xc5c5c5c5U, 0x89898989U,
0x6f6f6f6fU, 0xb7b7b7b7U, 0x62626262U, 0x0e0e0e0eU,
0xaaaaaaaaU, 0x18181818U, 0xbebebebeU, 0x1b1b1b1bU,
0xfcfcfcfcU, 0x56565656U, 0x3e3e3e3eU, 0x4b4b4b4bU,
0xc6c6c6c6U, 0xd2d2d2d2U, 0x79797979U, 0x20202020U,
0x9a9a9a9aU, 0xdbdbdbdbU, 0xc0c0c0c0U, 0xfefefefeU,
0x78787878U, 0xcdcdcdcdU, 0x5a5a5a5aU, 0xf4f4f4f4U,
0x1f1f1f1fU, 0xddddddddU, 0xa8a8a8a8U, 0x33333333U,
0x88888888U, 0x07070707U, 0xc7c7c7c7U, 0x31313131U,
0xb1b1b1b1U, 0x12121212U, 0x10101010U, 0x59595959U,
0x27272727U, 0x80808080U, 0xececececU, 0x5f5f5f5fU,
0x60606060U, 0x51515151U, 0x7f7f7f7fU, 0xa9a9a9a9U,
0x19191919U, 0xb5b5b5b5U, 0x4a4a4a4aU, 0x0d0d0d0dU,
0x2d2d2d2dU, 0xe5e5e5e5U, 0x7a7a7a7aU, 0x9f9f9f9fU,
0x93939393U, 0xc9c9c9c9U, 0x9c9c9c9cU, 0xefefefefU,
0xa0a0a0a0U, 0xe0e0e0e0U, 0x3b3b3b3bU, 0x4d4d4d4dU,
0xaeaeaeaeU, 0x2a2a2a2aU, 0xf5f5f5f5U, 0xb0b0b0b0U,
0xc8c8c8c8U, 0xebebebebU, 0xbbbbbbbbU, 0x3c3c3c3cU,
0x83838383U, 0x53535353U, 0x99999999U, 0x61616161U,
0x17171717U, 0x2b2b2b2bU, 0x04040404U, 0x7e7e7e7eU,
0xbabababaU, 0x77777777U, 0xd6d6d6d6U, 0x26262626U,
0xe1e1e1e1U, 0x69696969U, 0x14141414U, 0x63636363U,
0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU,
};
const word32 AES::rcon_[] = {
0x01000000, 0x02000000, 0x04000000, 0x08000000,
0x10000000, 0x20000000, 0x40000000, 0x80000000,

View File

@ -20,6 +20,8 @@
*/
/* based on Wei Dai's algebra.cpp from CryptoPP */
#undef NDEBUG
#define DEBUG // GCC 4.0 bug if NDEBUG and Optimize > 1
#include "runtime.hpp"
#include "algebra.hpp"

View File

@ -25,6 +25,11 @@
#include "arc4.hpp"
#if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
#define DO_ARC4_ASM
#endif
namespace TaoCrypt {
void ARC4::SetKey(const byte* key, word32 length)
@ -71,6 +76,8 @@ inline unsigned int MakeByte(word32& x, word32& y, byte* s)
} // namespace
#ifndef DO_ARC4_ASM
void ARC4::Process(byte* out, const byte* in, word32 length)
{
if (length == 0) return;
@ -89,5 +96,134 @@ void ARC4::Process(byte* out, const byte* in, word32 length)
y_ = y;
}
#else // DO_ARC4_ASM
#ifdef _MSC_VER
__declspec(naked)
#endif
void ARC4::Process(byte* out, const byte* in, word32 length)
{
#ifdef __GNUC__
#define AS1(x) asm(#x);
#define AS2(x, y) asm(#x ", " #y);
#define PROLOG() \
asm(".intel_syntax noprefix"); \
AS2( movd mm3, edi ) \
AS2( movd mm4, ebx ) \
AS2( movd mm5, esi ) \
AS2( movd mm6, ebp ) \
AS2( mov ecx, DWORD PTR [ebp + 8] ) \
AS2( mov edi, DWORD PTR [ebp + 12] ) \
AS2( mov esi, DWORD PTR [ebp + 16] ) \
AS2( mov ebp, DWORD PTR [ebp + 20] )
#define EPILOG() \
AS2( movd ebp, mm6 ) \
AS2( movd esi, mm5 ) \
AS2( movd ebx, mm4 ) \
AS2( mov esp, ebp ) \
AS2( movd edi, mm3 ) \
AS1( emms ) \
asm(".att_syntax");
#else
#define AS1(x) __asm x
#define AS2(x, y) __asm x, y
#define PROLOG() \
AS1( push ebp ) \
AS2( mov ebp, esp ) \
AS2( movd mm3, edi ) \
AS2( movd mm4, ebx ) \
AS2( movd mm5, esi ) \
AS2( movd mm6, ebp ) \
AS2( mov edi, DWORD PTR [ebp + 8] ) \
AS2( mov esi, DWORD PTR [ebp + 12] ) \
AS2( mov ebp, DWORD PTR [ebp + 16] )
#define EPILOG() \
AS2( movd ebp, mm6 ) \
AS2( movd esi, mm5 ) \
AS2( movd ebx, mm4 ) \
AS2( movd edi, mm3 ) \
AS2( mov esp, ebp ) \
AS1( pop ebp ) \
AS1( emms ) \
AS1( ret 12 )
#endif
PROLOG()
AS2( sub esp, 4 ) // make room
AS2( cmp ebp, 0 )
AS1( jz nothing )
AS2( mov [esp], ebp ) // length
AS2( movzx edx, BYTE PTR [ecx + 1] ) // y
AS2( lea ebp, [ecx + 2] ) // state_
AS2( movzx ecx, BYTE PTR [ecx] ) // x
// setup loop
// a = s[x];
AS2( movzx eax, BYTE PTR [ebp + ecx] )
AS1( begin: )
// y = (y+a) & 0xff;
AS2( add edx, eax )
AS2( and edx, 255 )
// b = s[y];
AS2( movzx ebx, BYTE PTR [ebp + edx] )
// s[x] = b;
AS2( mov [ebp + ecx], bl )
// s[y] = a;
AS2( mov [ebp + edx], al )
// x = (x+1) & 0xff;
AS1( inc ecx )
AS2( and ecx, 255 )
//return s[(a+b) & 0xff];
AS2( add eax, ebx )
AS2( and eax, 255 )
AS2( movzx ebx, BYTE PTR [ebp + eax] )
// a = s[x]; for next round
AS2( movzx eax, BYTE PTR [ebp + ecx] )
// xOr w/ inByte
AS2( xor bl, BYTE PTR [esi] )
AS1( inc esi )
// write to outByte
AS2( mov [edi], bl )
AS1( inc edi )
AS1( dec DWORD PTR [esp] )
AS1( jnz begin )
// write back to x_ and y_
AS2( mov [ebp - 2], cl )
AS2( mov [ebp - 1], dl )
AS1( nothing: )
EPILOG()
}
#endif // DO_ARC4_ASM
} // namespace

View File

@ -186,7 +186,7 @@ PublicKey::PublicKey(const byte* k, word32 s) : key_(0), sz_(0)
void PublicKey::SetSize(word32 s)
{
sz_ = s;
key_ = new (tc) byte[sz_];
key_ = NEW_TC byte[sz_];
}
@ -198,7 +198,7 @@ void PublicKey::SetKey(const byte* k)
void PublicKey::AddToEnd(const byte* data, word32 len)
{
mySTL::auto_ptr<byte> tmp(new (tc) byte[sz_ + len], tcArrayDelete);
mySTL::auto_ptr<byte> tmp(NEW_TC byte[sz_ + len], tcArrayDelete);
memcpy(tmp.get(), key_, sz_);
memcpy(tmp.get() + sz_, data, len);
@ -217,7 +217,7 @@ Signer::Signer(const byte* k, word32 kSz, const char* n, const byte* h)
{
if (n) {
int sz = strlen(n);
name_ = new (tc) char[sz + 1];
name_ = NEW_TC char[sz + 1];
memcpy(name_, n, sz);
name_[sz] = 0;
}
@ -421,12 +421,13 @@ void DH_Decoder::Decode(DH& key)
}
CertDecoder::CertDecoder(Source& s, bool decode, SignerList* signers)
CertDecoder::CertDecoder(Source& s, bool decode, SignerList* signers,
bool noVerify, CertType ct)
: BER_Decoder(s), certBegin_(0), sigIndex_(0), sigLength_(0),
signature_(0), issuer_(0), subject_(0)
signature_(0), issuer_(0), subject_(0), verify_(!noVerify)
{
if (decode)
Decode(signers);
Decode(signers, ct);
}
@ -455,7 +456,7 @@ void CertDecoder::ReadHeader()
// Decode a x509v3 Certificate
void CertDecoder::Decode(SignerList* signers)
void CertDecoder::Decode(SignerList* signers, CertType ct)
{
if (source_.GetError().What()) return;
DecodeToKey();
@ -473,12 +474,16 @@ void CertDecoder::Decode(SignerList* signers)
return;
}
if (ct == CA) {
if ( memcmp(issuerHash_, subjectHash_, SHA::DIGEST_SIZE) == 0 ) {
if (!ValidateSelfSignature())
if (!ValidateSelfSignature() && verify_)
source_.SetError(SIG_CONFIRM_E);
}
else
if (!ValidateSignature(signers))
if (!ValidateSignature(signers) && verify_)
source_.SetError(SIG_OTHER_E);
}
else if (!ValidateSignature(signers) && verify_)
source_.SetError(SIG_OTHER_E);
}
@ -631,7 +636,7 @@ word32 CertDecoder::GetSignature()
}
sigLength_--;
signature_ = new (tc) byte[sigLength_];
signature_ = NEW_TC byte[sigLength_];
memcpy(signature_, source_.get_current(), sigLength_);
source_.advance(sigLength_);
@ -652,7 +657,7 @@ word32 CertDecoder::GetDigest()
sigLength_ = GetLength(source_);
signature_ = new (tc) byte[sigLength_];
signature_ = NEW_TC byte[sigLength_];
memcpy(signature_, source_.get_current(), sigLength_);
source_.advance(sigLength_);
@ -692,7 +697,7 @@ void CertDecoder::GetName(NameType nt)
if (id == COMMON_NAME) {
char*& ptr = (nt == ISSUER) ? issuer_ : subject_;
ptr = new (tc) char[strLen + 1];
ptr = NEW_TC char[strLen + 1];
memcpy(ptr, source_.get_current(), strLen);
ptr[strLen] = 0;
}
@ -734,7 +739,7 @@ void CertDecoder::GetDate(DateType dt)
memcpy(date, source_.get_current(), length);
source_.advance(length);
if (!ValidateDate(date, b, dt))
if (!ValidateDate(date, b, dt) && verify_)
if (dt == BEFORE)
source_.SetError(BEFORE_DATE_E);
else
@ -802,22 +807,22 @@ bool CertDecoder::ValidateSignature(SignerList* signers)
}
// RSA confirm
// confirm certificate signature
bool CertDecoder::ConfirmSignature(Source& pub)
{
HashType ht;
mySTL::auto_ptr<HASH> hasher(tcDelete);
if (signatureOID_ == MD5wRSA) {
hasher.reset(new (tc) MD5);
hasher.reset(NEW_TC MD5);
ht = MD5h;
}
else if (signatureOID_ == MD2wRSA) {
hasher.reset(new (tc) MD2);
hasher.reset(NEW_TC MD2);
ht = MD2h;
}
else if (signatureOID_ == SHAwRSA || signatureOID_ == SHAwDSA) {
hasher.reset(new (tc) SHA);
hasher.reset(NEW_TC SHA);
ht = SHAh;
}
else {

View File

@ -0,0 +1,306 @@
/* bftables.cpp
*
* Copyright (C) 2003 Sawtooth Consulting Ltd.
*
* This file is part of yaSSL.
*
* yaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* yaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/* based on Wei Dai's bfinit.cpp from CryptoPP */
#include "runtime.hpp"
#include "blowfish.hpp"
namespace TaoCrypt {
const word32 Blowfish::p_init_[Blowfish::ROUNDS+2] =
{
608135816U, 2242054355U, 320440878U, 57701188U,
2752067618U, 698298832U, 137296536U, 3964562569U,
1160258022U, 953160567U, 3193202383U, 887688300U,
3232508343U, 3380367581U, 1065670069U, 3041331479U,
2450970073U, 2306472731U
} ;
const word32 Blowfish::s_init_[4*256] = {
3509652390U, 2564797868U, 805139163U, 3491422135U,
3101798381U, 1780907670U, 3128725573U, 4046225305U,
614570311U, 3012652279U, 134345442U, 2240740374U,
1667834072U, 1901547113U, 2757295779U, 4103290238U,
227898511U, 1921955416U, 1904987480U, 2182433518U,
2069144605U, 3260701109U, 2620446009U, 720527379U,
3318853667U, 677414384U, 3393288472U, 3101374703U,
2390351024U, 1614419982U, 1822297739U, 2954791486U,
3608508353U, 3174124327U, 2024746970U, 1432378464U,
3864339955U, 2857741204U, 1464375394U, 1676153920U,
1439316330U, 715854006U, 3033291828U, 289532110U,
2706671279U, 2087905683U, 3018724369U, 1668267050U,
732546397U, 1947742710U, 3462151702U, 2609353502U,
2950085171U, 1814351708U, 2050118529U, 680887927U,
999245976U, 1800124847U, 3300911131U, 1713906067U,
1641548236U, 4213287313U, 1216130144U, 1575780402U,
4018429277U, 3917837745U, 3693486850U, 3949271944U,
596196993U, 3549867205U, 258830323U, 2213823033U,
772490370U, 2760122372U, 1774776394U, 2652871518U,
566650946U, 4142492826U, 1728879713U, 2882767088U,
1783734482U, 3629395816U, 2517608232U, 2874225571U,
1861159788U, 326777828U, 3124490320U, 2130389656U,
2716951837U, 967770486U, 1724537150U, 2185432712U,
2364442137U, 1164943284U, 2105845187U, 998989502U,
3765401048U, 2244026483U, 1075463327U, 1455516326U,
1322494562U, 910128902U, 469688178U, 1117454909U,
936433444U, 3490320968U, 3675253459U, 1240580251U,
122909385U, 2157517691U, 634681816U, 4142456567U,
3825094682U, 3061402683U, 2540495037U, 79693498U,
3249098678U, 1084186820U, 1583128258U, 426386531U,
1761308591U, 1047286709U, 322548459U, 995290223U,
1845252383U, 2603652396U, 3431023940U, 2942221577U,
3202600964U, 3727903485U, 1712269319U, 422464435U,
3234572375U, 1170764815U, 3523960633U, 3117677531U,
1434042557U, 442511882U, 3600875718U, 1076654713U,
1738483198U, 4213154764U, 2393238008U, 3677496056U,
1014306527U, 4251020053U, 793779912U, 2902807211U,
842905082U, 4246964064U, 1395751752U, 1040244610U,
2656851899U, 3396308128U, 445077038U, 3742853595U,
3577915638U, 679411651U, 2892444358U, 2354009459U,
1767581616U, 3150600392U, 3791627101U, 3102740896U,
284835224U, 4246832056U, 1258075500U, 768725851U,
2589189241U, 3069724005U, 3532540348U, 1274779536U,
3789419226U, 2764799539U, 1660621633U, 3471099624U,
4011903706U, 913787905U, 3497959166U, 737222580U,
2514213453U, 2928710040U, 3937242737U, 1804850592U,
3499020752U, 2949064160U, 2386320175U, 2390070455U,
2415321851U, 4061277028U, 2290661394U, 2416832540U,
1336762016U, 1754252060U, 3520065937U, 3014181293U,
791618072U, 3188594551U, 3933548030U, 2332172193U,
3852520463U, 3043980520U, 413987798U, 3465142937U,
3030929376U, 4245938359U, 2093235073U, 3534596313U,
375366246U, 2157278981U, 2479649556U, 555357303U,
3870105701U, 2008414854U, 3344188149U, 4221384143U,
3956125452U, 2067696032U, 3594591187U, 2921233993U,
2428461U, 544322398U, 577241275U, 1471733935U,
610547355U, 4027169054U, 1432588573U, 1507829418U,
2025931657U, 3646575487U, 545086370U, 48609733U,
2200306550U, 1653985193U, 298326376U, 1316178497U,
3007786442U, 2064951626U, 458293330U, 2589141269U,
3591329599U, 3164325604U, 727753846U, 2179363840U,
146436021U, 1461446943U, 4069977195U, 705550613U,
3059967265U, 3887724982U, 4281599278U, 3313849956U,
1404054877U, 2845806497U, 146425753U, 1854211946U,
1266315497U, 3048417604U, 3681880366U, 3289982499U,
2909710000U, 1235738493U, 2632868024U, 2414719590U,
3970600049U, 1771706367U, 1449415276U, 3266420449U,
422970021U, 1963543593U, 2690192192U, 3826793022U,
1062508698U, 1531092325U, 1804592342U, 2583117782U,
2714934279U, 4024971509U, 1294809318U, 4028980673U,
1289560198U, 2221992742U, 1669523910U, 35572830U,
157838143U, 1052438473U, 1016535060U, 1802137761U,
1753167236U, 1386275462U, 3080475397U, 2857371447U,
1040679964U, 2145300060U, 2390574316U, 1461121720U,
2956646967U, 4031777805U, 4028374788U, 33600511U,
2920084762U, 1018524850U, 629373528U, 3691585981U,
3515945977U, 2091462646U, 2486323059U, 586499841U,
988145025U, 935516892U, 3367335476U, 2599673255U,
2839830854U, 265290510U, 3972581182U, 2759138881U,
3795373465U, 1005194799U, 847297441U, 406762289U,
1314163512U, 1332590856U, 1866599683U, 4127851711U,
750260880U, 613907577U, 1450815602U, 3165620655U,
3734664991U, 3650291728U, 3012275730U, 3704569646U,
1427272223U, 778793252U, 1343938022U, 2676280711U,
2052605720U, 1946737175U, 3164576444U, 3914038668U,
3967478842U, 3682934266U, 1661551462U, 3294938066U,
4011595847U, 840292616U, 3712170807U, 616741398U,
312560963U, 711312465U, 1351876610U, 322626781U,
1910503582U, 271666773U, 2175563734U, 1594956187U,
70604529U, 3617834859U, 1007753275U, 1495573769U,
4069517037U, 2549218298U, 2663038764U, 504708206U,
2263041392U, 3941167025U, 2249088522U, 1514023603U,
1998579484U, 1312622330U, 694541497U, 2582060303U,
2151582166U, 1382467621U, 776784248U, 2618340202U,
3323268794U, 2497899128U, 2784771155U, 503983604U,
4076293799U, 907881277U, 423175695U, 432175456U,
1378068232U, 4145222326U, 3954048622U, 3938656102U,
3820766613U, 2793130115U, 2977904593U, 26017576U,
3274890735U, 3194772133U, 1700274565U, 1756076034U,
4006520079U, 3677328699U, 720338349U, 1533947780U,
354530856U, 688349552U, 3973924725U, 1637815568U,
332179504U, 3949051286U, 53804574U, 2852348879U,
3044236432U, 1282449977U, 3583942155U, 3416972820U,
4006381244U, 1617046695U, 2628476075U, 3002303598U,
1686838959U, 431878346U, 2686675385U, 1700445008U,
1080580658U, 1009431731U, 832498133U, 3223435511U,
2605976345U, 2271191193U, 2516031870U, 1648197032U,
4164389018U, 2548247927U, 300782431U, 375919233U,
238389289U, 3353747414U, 2531188641U, 2019080857U,
1475708069U, 455242339U, 2609103871U, 448939670U,
3451063019U, 1395535956U, 2413381860U, 1841049896U,
1491858159U, 885456874U, 4264095073U, 4001119347U,
1565136089U, 3898914787U, 1108368660U, 540939232U,
1173283510U, 2745871338U, 3681308437U, 4207628240U,
3343053890U, 4016749493U, 1699691293U, 1103962373U,
3625875870U, 2256883143U, 3830138730U, 1031889488U,
3479347698U, 1535977030U, 4236805024U, 3251091107U,
2132092099U, 1774941330U, 1199868427U, 1452454533U,
157007616U, 2904115357U, 342012276U, 595725824U,
1480756522U, 206960106U, 497939518U, 591360097U,
863170706U, 2375253569U, 3596610801U, 1814182875U,
2094937945U, 3421402208U, 1082520231U, 3463918190U,
2785509508U, 435703966U, 3908032597U, 1641649973U,
2842273706U, 3305899714U, 1510255612U, 2148256476U,
2655287854U, 3276092548U, 4258621189U, 236887753U,
3681803219U, 274041037U, 1734335097U, 3815195456U,
3317970021U, 1899903192U, 1026095262U, 4050517792U,
356393447U, 2410691914U, 3873677099U, 3682840055U,
3913112168U, 2491498743U, 4132185628U, 2489919796U,
1091903735U, 1979897079U, 3170134830U, 3567386728U,
3557303409U, 857797738U, 1136121015U, 1342202287U,
507115054U, 2535736646U, 337727348U, 3213592640U,
1301675037U, 2528481711U, 1895095763U, 1721773893U,
3216771564U, 62756741U, 2142006736U, 835421444U,
2531993523U, 1442658625U, 3659876326U, 2882144922U,
676362277U, 1392781812U, 170690266U, 3921047035U,
1759253602U, 3611846912U, 1745797284U, 664899054U,
1329594018U, 3901205900U, 3045908486U, 2062866102U,
2865634940U, 3543621612U, 3464012697U, 1080764994U,
553557557U, 3656615353U, 3996768171U, 991055499U,
499776247U, 1265440854U, 648242737U, 3940784050U,
980351604U, 3713745714U, 1749149687U, 3396870395U,
4211799374U, 3640570775U, 1161844396U, 3125318951U,
1431517754U, 545492359U, 4268468663U, 3499529547U,
1437099964U, 2702547544U, 3433638243U, 2581715763U,
2787789398U, 1060185593U, 1593081372U, 2418618748U,
4260947970U, 69676912U, 2159744348U, 86519011U,
2512459080U, 3838209314U, 1220612927U, 3339683548U,
133810670U, 1090789135U, 1078426020U, 1569222167U,
845107691U, 3583754449U, 4072456591U, 1091646820U,
628848692U, 1613405280U, 3757631651U, 526609435U,
236106946U, 48312990U, 2942717905U, 3402727701U,
1797494240U, 859738849U, 992217954U, 4005476642U,
2243076622U, 3870952857U, 3732016268U, 765654824U,
3490871365U, 2511836413U, 1685915746U, 3888969200U,
1414112111U, 2273134842U, 3281911079U, 4080962846U,
172450625U, 2569994100U, 980381355U, 4109958455U,
2819808352U, 2716589560U, 2568741196U, 3681446669U,
3329971472U, 1835478071U, 660984891U, 3704678404U,
4045999559U, 3422617507U, 3040415634U, 1762651403U,
1719377915U, 3470491036U, 2693910283U, 3642056355U,
3138596744U, 1364962596U, 2073328063U, 1983633131U,
926494387U, 3423689081U, 2150032023U, 4096667949U,
1749200295U, 3328846651U, 309677260U, 2016342300U,
1779581495U, 3079819751U, 111262694U, 1274766160U,
443224088U, 298511866U, 1025883608U, 3806446537U,
1145181785U, 168956806U, 3641502830U, 3584813610U,
1689216846U, 3666258015U, 3200248200U, 1692713982U,
2646376535U, 4042768518U, 1618508792U, 1610833997U,
3523052358U, 4130873264U, 2001055236U, 3610705100U,
2202168115U, 4028541809U, 2961195399U, 1006657119U,
2006996926U, 3186142756U, 1430667929U, 3210227297U,
1314452623U, 4074634658U, 4101304120U, 2273951170U,
1399257539U, 3367210612U, 3027628629U, 1190975929U,
2062231137U, 2333990788U, 2221543033U, 2438960610U,
1181637006U, 548689776U, 2362791313U, 3372408396U,
3104550113U, 3145860560U, 296247880U, 1970579870U,
3078560182U, 3769228297U, 1714227617U, 3291629107U,
3898220290U, 166772364U, 1251581989U, 493813264U,
448347421U, 195405023U, 2709975567U, 677966185U,
3703036547U, 1463355134U, 2715995803U, 1338867538U,
1343315457U, 2802222074U, 2684532164U, 233230375U,
2599980071U, 2000651841U, 3277868038U, 1638401717U,
4028070440U, 3237316320U, 6314154U, 819756386U,
300326615U, 590932579U, 1405279636U, 3267499572U,
3150704214U, 2428286686U, 3959192993U, 3461946742U,
1862657033U, 1266418056U, 963775037U, 2089974820U,
2263052895U, 1917689273U, 448879540U, 3550394620U,
3981727096U, 150775221U, 3627908307U, 1303187396U,
508620638U, 2975983352U, 2726630617U, 1817252668U,
1876281319U, 1457606340U, 908771278U, 3720792119U,
3617206836U, 2455994898U, 1729034894U, 1080033504U,
976866871U, 3556439503U, 2881648439U, 1522871579U,
1555064734U, 1336096578U, 3548522304U, 2579274686U,
3574697629U, 3205460757U, 3593280638U, 3338716283U,
3079412587U, 564236357U, 2993598910U, 1781952180U,
1464380207U, 3163844217U, 3332601554U, 1699332808U,
1393555694U, 1183702653U, 3581086237U, 1288719814U,
691649499U, 2847557200U, 2895455976U, 3193889540U,
2717570544U, 1781354906U, 1676643554U, 2592534050U,
3230253752U, 1126444790U, 2770207658U, 2633158820U,
2210423226U, 2615765581U, 2414155088U, 3127139286U,
673620729U, 2805611233U, 1269405062U, 4015350505U,
3341807571U, 4149409754U, 1057255273U, 2012875353U,
2162469141U, 2276492801U, 2601117357U, 993977747U,
3918593370U, 2654263191U, 753973209U, 36408145U,
2530585658U, 25011837U, 3520020182U, 2088578344U,
530523599U, 2918365339U, 1524020338U, 1518925132U,
3760827505U, 3759777254U, 1202760957U, 3985898139U,
3906192525U, 674977740U, 4174734889U, 2031300136U,
2019492241U, 3983892565U, 4153806404U, 3822280332U,
352677332U, 2297720250U, 60907813U, 90501309U,
3286998549U, 1016092578U, 2535922412U, 2839152426U,
457141659U, 509813237U, 4120667899U, 652014361U,
1966332200U, 2975202805U, 55981186U, 2327461051U,
676427537U, 3255491064U, 2882294119U, 3433927263U,
1307055953U, 942726286U, 933058658U, 2468411793U,
3933900994U, 4215176142U, 1361170020U, 2001714738U,
2830558078U, 3274259782U, 1222529897U, 1679025792U,
2729314320U, 3714953764U, 1770335741U, 151462246U,
3013232138U, 1682292957U, 1483529935U, 471910574U,
1539241949U, 458788160U, 3436315007U, 1807016891U,
3718408830U, 978976581U, 1043663428U, 3165965781U,
1927990952U, 4200891579U, 2372276910U, 3208408903U,
3533431907U, 1412390302U, 2931980059U, 4132332400U,
1947078029U, 3881505623U, 4168226417U, 2941484381U,
1077988104U, 1320477388U, 886195818U, 18198404U,
3786409000U, 2509781533U, 112762804U, 3463356488U,
1866414978U, 891333506U, 18488651U, 661792760U,
1628790961U, 3885187036U, 3141171499U, 876946877U,
2693282273U, 1372485963U, 791857591U, 2686433993U,
3759982718U, 3167212022U, 3472953795U, 2716379847U,
445679433U, 3561995674U, 3504004811U, 3574258232U,
54117162U, 3331405415U, 2381918588U, 3769707343U,
4154350007U, 1140177722U, 4074052095U, 668550556U,
3214352940U, 367459370U, 261225585U, 2610173221U,
4209349473U, 3468074219U, 3265815641U, 314222801U,
3066103646U, 3808782860U, 282218597U, 3406013506U,
3773591054U, 379116347U, 1285071038U, 846784868U,
2669647154U, 3771962079U, 3550491691U, 2305946142U,
453669953U, 1268987020U, 3317592352U, 3279303384U,
3744833421U, 2610507566U, 3859509063U, 266596637U,
3847019092U, 517658769U, 3462560207U, 3443424879U,
370717030U, 4247526661U, 2224018117U, 4143653529U,
4112773975U, 2788324899U, 2477274417U, 1456262402U,
2901442914U, 1517677493U, 1846949527U, 2295493580U,
3734397586U, 2176403920U, 1280348187U, 1908823572U,
3871786941U, 846861322U, 1172426758U, 3287448474U,
3383383037U, 1655181056U, 3139813346U, 901632758U,
1897031941U, 2986607138U, 3066810236U, 3447102507U,
1393639104U, 373351379U, 950779232U, 625454576U,
3124240540U, 4148612726U, 2007998917U, 544563296U,
2244738638U, 2330496472U, 2058025392U, 1291430526U,
424198748U, 50039436U, 29584100U, 3605783033U,
2429876329U, 2791104160U, 1057563949U, 3255363231U,
3075367218U, 3463963227U, 1469046755U, 985887462U
};
} // namespace

View File

@ -0,0 +1,358 @@
/* blowfish.cpp
*
* Copyright (C) 2003 Sawtooth Consulting Ltd.
*
* This file is part of yaSSL.
*
* yaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* yaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/* C++ code based on Wei Dai's blowfish.cpp from CryptoPP */
/* x86 asm is original */
#if defined(TAOCRYPT_KERNEL_MODE)
#define DO_TAOCRYPT_KERNEL_MODE
#endif // only some modules now support this
#include "runtime.hpp"
#include "blowfish.hpp"
#if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
#define DO_BLOWFISH_ASM
#endif
namespace TaoCrypt {
#if !defined(DO_BLOWFISH_ASM)
// Generic Version
void Blowfish::Process(byte* out, const byte* in, word32 sz)
{
if (mode_ == ECB)
ECB_Process(out, in, sz);
else if (mode_ == CBC)
if (dir_ == ENCRYPTION)
CBC_Encrypt(out, in, sz);
else
CBC_Decrypt(out, in, sz);
}
#else
// ia32 optimized version
void Blowfish::Process(byte* out, const byte* in, word32 sz)
{
word32 blocks = sz / BLOCK_SIZE;
if (mode_ == ECB)
while (blocks--) {
AsmProcess(in, out);
out += BLOCK_SIZE;
in += BLOCK_SIZE;
}
else if (mode_ == CBC)
if (dir_ == ENCRYPTION)
while (blocks--) {
r_[0] ^= *(word32*)in;
r_[1] ^= *(word32*)(in + 4);
AsmProcess((byte*)r_, (byte*)r_);
memcpy(out, r_, BLOCK_SIZE);
out += BLOCK_SIZE;
in += BLOCK_SIZE;
}
else
while (blocks--) {
AsmProcess(in, out);
*(word32*)out ^= r_[0];
*(word32*)(out + 4) ^= r_[1];
memcpy(r_, in, BLOCK_SIZE);
out += BLOCK_SIZE;
in += BLOCK_SIZE;
}
}
#endif // DO_BLOWFISH_ASM
void Blowfish::SetKey(const byte* key_string, word32 keylength, CipherDir dir)
{
assert(keylength >= 4 && keylength <= 56);
unsigned i, j=0, k;
word32 data, dspace[2] = {0, 0};
memcpy(pbox_, p_init_, sizeof(p_init_));
memcpy(sbox_, s_init_, sizeof(s_init_));
// Xor key string into encryption key vector
for (i=0 ; i<ROUNDS+2 ; ++i) {
data = 0;
for (k=0 ; k<4 ; ++k )
data = (data << 8) | key_string[j++ % keylength];
pbox_[i] ^= data;
}
crypt_block(dspace, pbox_);
for (i=0; i<ROUNDS; i+=2)
crypt_block(pbox_ + i, pbox_ + i + 2);
crypt_block(pbox_ + ROUNDS, sbox_);
for (i=0; i < 4*256-2; i+=2)
crypt_block(sbox_ + i, sbox_ + i + 2);
if (dir==DECRYPTION)
for (i=0; i<(ROUNDS+2)/2; i++)
mySTL::swap(pbox_[i], pbox_[ROUNDS+1-i]);
}
#define BFBYTE_0(x) ( x &0xFF)
#define BFBYTE_1(x) ((x>> 8)&0xFF)
#define BFBYTE_2(x) ((x>>16)&0xFF)
#define BFBYTE_3(x) ( x>>24)
#define BF_S(Put, Get, I) (\
Put ^= p[I], \
tmp = p[18 + BFBYTE_3(Get)], \
tmp += p[274+ BFBYTE_2(Get)], \
tmp ^= p[530+ BFBYTE_1(Get)], \
tmp += p[786+ BFBYTE_0(Get)], \
Put ^= tmp \
)
#define BF_ROUNDS \
BF_S(right, left, 1); \
BF_S(left, right, 2); \
BF_S(right, left, 3); \
BF_S(left, right, 4); \
BF_S(right, left, 5); \
BF_S(left, right, 6); \
BF_S(right, left, 7); \
BF_S(left, right, 8); \
BF_S(right, left, 9); \
BF_S(left, right, 10); \
BF_S(right, left, 11); \
BF_S(left, right, 12); \
BF_S(right, left, 13); \
BF_S(left, right, 14); \
BF_S(right, left, 15); \
BF_S(left, right, 16);
#define BF_EXTRA_ROUNDS \
BF_S(right, left, 17); \
BF_S(left, right, 18); \
BF_S(right, left, 19); \
BF_S(left, right, 20);
// Used by key setup, no byte swapping
void Blowfish::crypt_block(const word32 in[2], word32 out[2]) const
{
word32 left = in[0];
word32 right = in[1];
const word32* p = pbox_;
word32 tmp;
left ^= p[0];
BF_ROUNDS
#if ROUNDS == 20
BF_EXTRA_ROUNDS
#endif
right ^= p[ROUNDS + 1];
out[0] = right;
out[1] = left;
}
typedef BlockGetAndPut<word32, BigEndian> gpBlock;
void Blowfish::ProcessAndXorBlock(const byte* in, const byte* xOr, byte* out)
const
{
word32 tmp, left, right;
const word32* p = pbox_;
gpBlock::Get(in)(left)(right);
left ^= p[0];
BF_ROUNDS
#if ROUNDS == 20
BF_EXTRA_ROUNDS
#endif
right ^= p[ROUNDS + 1];
gpBlock::Put(xOr, out)(right)(left);
}
#if defined(DO_BLOWFISH_ASM)
#ifdef __GNUC__
#define AS1(x) asm(#x);
#define AS2(x, y) asm(#x ", " #y);
#define PROLOG() \
asm(".intel_syntax noprefix"); \
AS2( movd mm3, edi ) \
AS2( movd mm4, ebx ) \
AS2( movd mm5, esi ) \
AS2( mov ecx, DWORD PTR [ebp + 8] ) \
AS2( mov esi, DWORD PTR [ebp + 12] )
#define EPILOG() \
AS2( movd esi, mm5 ) \
AS2( movd ebx, mm4 ) \
AS2( movd edi, mm3 ) \
AS1( emms ) \
asm(".att_syntax");
#else
#define AS1(x) __asm x
#define AS2(x, y) __asm x, y
#define PROLOG() \
AS1( push ebp ) \
AS2( mov ebp, esp ) \
AS2( movd mm3, edi ) \
AS2( movd mm4, ebx ) \
AS2( movd mm5, esi ) \
AS2( mov esi, DWORD PTR [ebp + 8] )
#define EPILOG() \
AS2( movd esi, mm5 ) \
AS2( movd ebx, mm4 ) \
AS2( movd edi, mm3 ) \
AS2( mov esp, ebp ) \
AS1( pop ebp ) \
AS1( emms ) \
AS1( ret 8 )
#endif
#define BF_ROUND(P, G, I) \
/* Put ^= p[I] */ \
AS2( xor P, [edi + I*4] ) \
/* tmp = p[18 + BFBYTE_3(Get)] */ \
AS2( mov ecx, G ) \
AS2( shr ecx, 16 ) \
AS2( movzx edx, ch ) \
AS2( mov esi, [edi + edx*4 + 72] ) \
/* tmp += p[274+ BFBYTE_2(Get)] */ \
AS2( movzx ecx, cl ) \
AS2( add esi, [edi + ecx*4 + 1096] ) \
/* tmp ^= p[530+ BFBYTE_1(Get)] */ \
AS2( mov ecx, G ) \
AS2( movzx edx, ch ) \
AS2( xor esi, [edi + edx*4 + 2120] ) \
/* tmp += p[786+ BFBYTE_0(Get)] */ \
AS2( movzx ecx, cl ) \
AS2( add esi, [edi + ecx*4 + 3144] ) \
/* Put ^= tmp */ \
AS2( xor P, esi )
#ifdef _MSC_VER
__declspec(naked)
#endif
void Blowfish::AsmProcess(const byte* inBlock, byte* outBlock) const
{
PROLOG()
#ifdef OLD_GCC_OFFSET
AS2( lea edi, [ecx + 60] ) // pbox
#else
AS2( lea edi, [ecx + 56] ) // pbox
#endif
AS2( mov eax, DWORD PTR [esi] )
AS2( mov edx, DWORD PTR [edi] )
AS1( bswap eax )
AS2( mov ebx, DWORD PTR [esi + 4] )
AS2( xor eax, edx ) // left
AS1( bswap ebx ) // right
BF_ROUND(ebx, eax, 1)
BF_ROUND(eax, ebx, 2)
BF_ROUND(ebx, eax, 3)
BF_ROUND(eax, ebx, 4)
BF_ROUND(ebx, eax, 5)
BF_ROUND(eax, ebx, 6)
BF_ROUND(ebx, eax, 7)
BF_ROUND(eax, ebx, 8)
BF_ROUND(ebx, eax, 9)
BF_ROUND(eax, ebx, 10)
BF_ROUND(ebx, eax, 11)
BF_ROUND(eax, ebx, 12)
BF_ROUND(ebx, eax, 13)
BF_ROUND(eax, ebx, 14)
BF_ROUND(ebx, eax, 15)
BF_ROUND(eax, ebx, 16)
#if ROUNDS == 20
BF_ROUND(ebx, eax, 17)
BF_ROUND(eax, ebx, 18)
BF_ROUND(ebx, eax, 19)
BF_ROUND(eax, ebx, 20)
AS2( xor ebx, [edi + 84] ) // 20 + 1 (x4)
#else
AS2( xor ebx, [edi + 68] ) // 16 + 1 (x4)
#endif
#ifdef __GNUC__
AS2( mov edi, [ebp + 16] ) // outBlock
#else
AS2( mov edi, [ebp + 12] ) // outBlock
#endif
AS1( bswap ebx )
AS1( bswap eax )
AS2( mov [edi] , ebx )
AS2( mov [edi + 4], eax )
EPILOG()
}
#endif // DO_BLOWFISH_ASM
} // namespace

View File

@ -130,7 +130,7 @@ void Base64Encoder::Encode()
word32 outSz = bytes * 4 / 3;
outSz += (outSz % 4); // 4 byte integrals
outSz += outSz / pemLineSz + ( (outSz % pemLineSz) ? 1 : 0); // new lines
outSz += (outSz + pemLineSz - 1) / pemLineSz; // new lines
encoded_.New(outSz);
word32 i = 0;
@ -187,9 +187,8 @@ void Base64Encoder::Encode()
void Base64Decoder::Decode()
{
word32 bytes = coded_.size();
word32 plainSz = bytes - (bytes / pemLineSz + ( (bytes % pemLineSz) ?
1 : 0));
plainSz = plainSz * 3 / 4 + (( (plainSz * 3) % 4) ? 1 : 0);
word32 plainSz = bytes - ((bytes + (pemLineSz - 1)) / pemLineSz);
plainSz = (plainSz * 3 + 3) / 4;
decoded_.New(plainSz);
word32 i = 0;

View File

@ -19,14 +19,25 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/* based on Wei Dai's des.cpp from CryptoPP */
/* C++ part based on Wei Dai's des.cpp from CryptoPP */
/* x86 asm is original */
#if defined(TAOCRYPT_KERNEL_MODE)
#define DO_TAOCRYPT_KERNEL_MODE
#endif // only some modules now support this
#include "runtime.hpp"
#include "des.hpp"
#include <string.h>
#include "algorithm.hpp" // mySTL::swap
#if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
#define DO_DES_ASM
#endif
namespace TaoCrypt {
@ -67,101 +78,7 @@ static const int bytebit[] = {
0200,0100,040,020,010,04,02,01
};
void DES::SetKey(const byte* key, word32 /*length*/, CipherDir dir)
{
byte buffer[56+56+8];
byte *const pc1m = buffer; /* place to modify pc1 into */
byte *const pcr = pc1m + 56; /* place to rotate pc1 into */
byte *const ks = pcr + 56;
register int i,j,l;
int m;
for (j = 0; j < 56; j++) { /* convert pc1 to bits of key */
l = pc1[j] - 1; /* integer bit location */
m = l & 07; /* find bit */
pc1m[j] = (key[l >> 3] & /* find which key byte l is in */
bytebit[m]) /* and which bit of that byte */
? 1 : 0; /* and store 1-bit result */
}
for (i = 0; i < 16; i++) { /* key chunk for each iteration */
memset(ks, 0, 8); /* Clear key schedule */
for (j = 0; j < 56; j++) /* rotate pc1 the right amount */
pcr[j] = pc1m[(l = j + totrot[i]) < (j < 28 ? 28 : 56) ? l: l-28];
/* rotate left and right halves independently */
for (j = 0; j < 48; j++){ /* select bits individually */
/* check bit that goes to ks[j] */
if (pcr[pc2[j] - 1]){
/* mask it in if it's there */
l= j % 6;
ks[j/6] |= bytebit[l] >> 2;
}
}
/* Now convert to odd/even interleaved form for use in F */
k_[2*i] = ((word32)ks[0] << 24)
| ((word32)ks[2] << 16)
| ((word32)ks[4] << 8)
| ((word32)ks[6]);
k_[2*i + 1] = ((word32)ks[1] << 24)
| ((word32)ks[3] << 16)
| ((word32)ks[5] << 8)
| ((word32)ks[7]);
}
// reverse key schedule order
if (dir == DECRYPTION)
for (i = 0; i < 16; i += 2) {
mySTL::swap(k_[i], k_[32 - 2 - i]);
mySTL::swap(k_[i+1], k_[32 - 1 - i]);
}
}
static inline void IPERM(word32& left, word32& right)
{
word32 work;
right = rotlFixed(right, 4U);
work = (left ^ right) & 0xf0f0f0f0;
left ^= work;
right = rotrFixed(right^work, 20U);
work = (left ^ right) & 0xffff0000;
left ^= work;
right = rotrFixed(right^work, 18U);
work = (left ^ right) & 0x33333333;
left ^= work;
right = rotrFixed(right^work, 6U);
work = (left ^ right) & 0x00ff00ff;
left ^= work;
right = rotlFixed(right^work, 9U);
work = (left ^ right) & 0xaaaaaaaa;
left = rotlFixed(left^work, 1U);
right ^= work;
}
static inline void FPERM(word32& left, word32& right)
{
word32 work;
right = rotrFixed(right, 1U);
work = (left ^ right) & 0xaaaaaaaa;
right ^= work;
left = rotrFixed(left^work, 9U);
work = (left ^ right) & 0x00ff00ff;
right ^= work;
left = rotlFixed(left^work, 6U);
work = (left ^ right) & 0x33333333;
right ^= work;
left = rotlFixed(left^work, 18U);
work = (left ^ right) & 0xffff0000;
right ^= work;
left = rotlFixed(left^work, 20U);
work = (left ^ right) & 0xf0f0f0f0;
right ^= work;
left = rotrFixed(left^work, 4U);
}
const word32 Spbox[DES::BOXES][DES::BOX_SIZE] = {
const word32 Spbox[8][64] = {
{
0x01010400,0x00000000,0x00010000,0x01010404,
0x01010004,0x00010404,0x00000004,0x00010000,
@ -301,8 +218,105 @@ const word32 Spbox[DES::BOXES][DES::BOX_SIZE] = {
};
void BasicDES::SetKey(const byte* key, word32 /*length*/, CipherDir dir)
{
byte buffer[56+56+8];
byte *const pc1m = buffer; /* place to modify pc1 into */
byte *const pcr = pc1m + 56; /* place to rotate pc1 into */
byte *const ks = pcr + 56;
register int i,j,l;
int m;
void DES::RawProcessBlock(word32& lIn, word32& rIn) const
for (j = 0; j < 56; j++) { /* convert pc1 to bits of key */
l = pc1[j] - 1; /* integer bit location */
m = l & 07; /* find bit */
pc1m[j] = (key[l >> 3] & /* find which key byte l is in */
bytebit[m]) /* and which bit of that byte */
? 1 : 0; /* and store 1-bit result */
}
for (i = 0; i < 16; i++) { /* key chunk for each iteration */
memset(ks, 0, 8); /* Clear key schedule */
for (j = 0; j < 56; j++) /* rotate pc1 the right amount */
pcr[j] = pc1m[(l = j + totrot[i]) < (j < 28 ? 28 : 56) ? l: l-28];
/* rotate left and right halves independently */
for (j = 0; j < 48; j++){ /* select bits individually */
/* check bit that goes to ks[j] */
if (pcr[pc2[j] - 1]){
/* mask it in if it's there */
l= j % 6;
ks[j/6] |= bytebit[l] >> 2;
}
}
/* Now convert to odd/even interleaved form for use in F */
k_[2*i] = ((word32)ks[0] << 24)
| ((word32)ks[2] << 16)
| ((word32)ks[4] << 8)
| ((word32)ks[6]);
k_[2*i + 1] = ((word32)ks[1] << 24)
| ((word32)ks[3] << 16)
| ((word32)ks[5] << 8)
| ((word32)ks[7]);
}
// reverse key schedule order
if (dir == DECRYPTION)
for (i = 0; i < 16; i += 2) {
mySTL::swap(k_[i], k_[32 - 2 - i]);
mySTL::swap(k_[i+1], k_[32 - 1 - i]);
}
}
static inline void IPERM(word32& left, word32& right)
{
word32 work;
right = rotlFixed(right, 4U);
work = (left ^ right) & 0xf0f0f0f0;
left ^= work;
right = rotrFixed(right^work, 20U);
work = (left ^ right) & 0xffff0000;
left ^= work;
right = rotrFixed(right^work, 18U);
work = (left ^ right) & 0x33333333;
left ^= work;
right = rotrFixed(right^work, 6U);
work = (left ^ right) & 0x00ff00ff;
left ^= work;
right = rotlFixed(right^work, 9U);
work = (left ^ right) & 0xaaaaaaaa;
left = rotlFixed(left^work, 1U);
right ^= work;
}
static inline void FPERM(word32& left, word32& right)
{
word32 work;
right = rotrFixed(right, 1U);
work = (left ^ right) & 0xaaaaaaaa;
right ^= work;
left = rotrFixed(left^work, 9U);
work = (left ^ right) & 0x00ff00ff;
right ^= work;
left = rotlFixed(left^work, 6U);
work = (left ^ right) & 0x33333333;
right ^= work;
left = rotlFixed(left^work, 18U);
work = (left ^ right) & 0xffff0000;
right ^= work;
left = rotlFixed(left^work, 20U);
work = (left ^ right) & 0xf0f0f0f0;
right ^= work;
left = rotrFixed(left^work, 4U);
}
void BasicDES::RawProcessBlock(word32& lIn, word32& rIn) const
{
word32 l = lIn, r = rIn;
const word32* kptr = k_;
@ -336,7 +350,7 @@ void DES::RawProcessBlock(word32& lIn, word32& rIn) const
}
void DES_BASE::Process(byte* out, const byte* in, word32 sz)
void DES::Process(byte* out, const byte* in, word32 sz)
{
if (mode_ == ECB)
ECB_Process(out, in, sz);
@ -358,38 +372,24 @@ void DES::ProcessAndXorBlock(const byte* in, const byte* xOr, byte* out) const
Block::Get(in)(l)(r);
IPERM(l,r);
const word32* kptr = k_;
for (unsigned i = 0; i < 8; i++)
{
word32 work = rotrFixed(r, 4U) ^ kptr[4*i+0];
l ^= Spbox[6][(work) & 0x3f]
^ Spbox[4][(work >> 8) & 0x3f]
^ Spbox[2][(work >> 16) & 0x3f]
^ Spbox[0][(work >> 24) & 0x3f];
work = r ^ kptr[4*i+1];
l ^= Spbox[7][(work) & 0x3f]
^ Spbox[5][(work >> 8) & 0x3f]
^ Spbox[3][(work >> 16) & 0x3f]
^ Spbox[1][(work >> 24) & 0x3f];
work = rotrFixed(l, 4U) ^ kptr[4*i+2];
r ^= Spbox[6][(work) & 0x3f]
^ Spbox[4][(work >> 8) & 0x3f]
^ Spbox[2][(work >> 16) & 0x3f]
^ Spbox[0][(work >> 24) & 0x3f];
work = l ^ kptr[4*i+3];
r ^= Spbox[7][(work) & 0x3f]
^ Spbox[5][(work >> 8) & 0x3f]
^ Spbox[3][(work >> 16) & 0x3f]
^ Spbox[1][(work >> 24) & 0x3f];
}
RawProcessBlock(l, r);
FPERM(l,r);
Block::Put(xOr, out)(r)(l);
}
void DES_EDE2::Process(byte* out, const byte* in, word32 sz)
{
if (mode_ == ECB)
ECB_Process(out, in, sz);
else if (mode_ == CBC)
if (dir_ == ENCRYPTION)
CBC_Encrypt(out, in, sz);
else
CBC_Decrypt(out, in, sz);
}
void DES_EDE2::SetKey(const byte* key, word32 sz, CipherDir dir)
{
des1_.SetKey(key, sz, dir);
@ -403,9 +403,11 @@ void DES_EDE2::ProcessAndXorBlock(const byte* in, const byte* xOr,
word32 l,r;
Block::Get(in)(l)(r);
IPERM(l,r);
des1_.RawProcessBlock(l, r);
des2_.RawProcessBlock(r, l);
des1_.RawProcessBlock(l, r);
FPERM(l,r);
Block::Put(xOr, out)(r)(l);
}
@ -418,18 +420,389 @@ void DES_EDE3::SetKey(const byte* key, word32 sz, CipherDir dir)
des3_.SetKey(key+(dir==DECRYPTION?0:2*8), sz, dir);
}
#if !defined(DO_DES_ASM)
// Generic Version
void DES_EDE3::Process(byte* out, const byte* in, word32 sz)
{
if (mode_ == ECB)
ECB_Process(out, in, sz);
else if (mode_ == CBC)
if (dir_ == ENCRYPTION)
CBC_Encrypt(out, in, sz);
else
CBC_Decrypt(out, in, sz);
}
#else
// ia32 optimized version
void DES_EDE3::Process(byte* out, const byte* in, word32 sz)
{
word32 blocks = sz / DES_BLOCK_SIZE;
if (mode_ == CBC)
if (dir_ == ENCRYPTION)
while (blocks--) {
r_[0] ^= *(word32*)in;
r_[1] ^= *(word32*)(in + 4);
AsmProcess((byte*)r_, (byte*)r_, (void*)Spbox);
memcpy(out, r_, DES_BLOCK_SIZE);
in += DES_BLOCK_SIZE;
out += DES_BLOCK_SIZE;
}
else
while (blocks--) {
AsmProcess(in, out, (void*)Spbox);
*(word32*)out ^= r_[0];
*(word32*)(out + 4) ^= r_[1];
memcpy(r_, in, DES_BLOCK_SIZE);
out += DES_BLOCK_SIZE;
in += DES_BLOCK_SIZE;
}
else
while (blocks--) {
AsmProcess(in, out, (void*)Spbox);
out += DES_BLOCK_SIZE;
in += DES_BLOCK_SIZE;
}
}
#endif // DO_DES_ASM
void DES_EDE3::ProcessAndXorBlock(const byte* in, const byte* xOr,
byte* out) const
{
word32 l,r;
Block::Get(in)(l)(r);
IPERM(l,r);
des1_.RawProcessBlock(l, r);
des2_.RawProcessBlock(r, l);
des3_.RawProcessBlock(l, r);
FPERM(l,r);
Block::Put(xOr, out)(r)(l);
}
#if defined(DO_DES_ASM)
/* Uses IPERM algorithm from above
left is in eax
right is in ebx
uses ecx
*/
#define AsmIPERM() {\
AS2( rol ebx, 4 ) \
AS2( mov ecx, eax ) \
AS2( xor ecx, ebx ) \
AS2( and ecx, 0xf0f0f0f0 ) \
AS2( xor ebx, ecx ) \
AS2( xor eax, ecx ) \
AS2( ror ebx, 20 ) \
AS2( mov ecx, eax ) \
AS2( xor ecx, ebx ) \
AS2( and ecx, 0xffff0000 ) \
AS2( xor ebx, ecx ) \
AS2( xor eax, ecx ) \
AS2( ror ebx, 18 ) \
AS2( mov ecx, eax ) \
AS2( xor ecx, ebx ) \
AS2( and ecx, 0x33333333 ) \
AS2( xor ebx, ecx ) \
AS2( xor eax, ecx ) \
AS2( ror ebx, 6 ) \
AS2( mov ecx, eax ) \
AS2( xor ecx, ebx ) \
AS2( and ecx, 0x00ff00ff ) \
AS2( xor ebx, ecx ) \
AS2( xor eax, ecx ) \
AS2( rol ebx, 9 ) \
AS2( mov ecx, eax ) \
AS2( xor ecx, ebx ) \
AS2( and ecx, 0xaaaaaaaa ) \
AS2( xor eax, ecx ) \
AS2( rol eax, 1 ) \
AS2( xor ebx, ecx ) }
/* Uses FPERM algorithm from above
left is in eax
right is in ebx
uses ecx
*/
#define AsmFPERM() {\
AS2( ror ebx, 1 ) \
AS2( mov ecx, eax ) \
AS2( xor ecx, ebx ) \
AS2( and ecx, 0xaaaaaaaa ) \
AS2( xor eax, ecx ) \
AS2( xor ebx, ecx ) \
AS2( ror eax, 9 ) \
AS2( mov ecx, ebx ) \
AS2( xor ecx, eax ) \
AS2( and ecx, 0x00ff00ff ) \
AS2( xor eax, ecx ) \
AS2( xor ebx, ecx ) \
AS2( rol eax, 6 ) \
AS2( mov ecx, ebx ) \
AS2( xor ecx, eax ) \
AS2( and ecx, 0x33333333 ) \
AS2( xor eax, ecx ) \
AS2( xor ebx, ecx ) \
AS2( rol eax, 18 ) \
AS2( mov ecx, ebx ) \
AS2( xor ecx, eax ) \
AS2( and ecx, 0xffff0000 ) \
AS2( xor eax, ecx ) \
AS2( xor ebx, ecx ) \
AS2( rol eax, 20 ) \
AS2( mov ecx, ebx ) \
AS2( xor ecx, eax ) \
AS2( and ecx, 0xf0f0f0f0 ) \
AS2( xor eax, ecx ) \
AS2( xor ebx, ecx ) \
AS2( ror eax, 4 ) }
/* DesRound implements this algorithm:
word32 work = rotrFixed(r, 4U) ^ key[0];
l ^= Spbox[6][(work) & 0x3f]
^ Spbox[4][(work >> 8) & 0x3f]
^ Spbox[2][(work >> 16) & 0x3f]
^ Spbox[0][(work >> 24) & 0x3f];
work = r ^ key[1];
l ^= Spbox[7][(work) & 0x3f]
^ Spbox[5][(work >> 8) & 0x3f]
^ Spbox[3][(work >> 16) & 0x3f]
^ Spbox[1][(work >> 24) & 0x3f];
work = rotrFixed(l, 4U) ^ key[2];
r ^= Spbox[6][(work) & 0x3f]
^ Spbox[4][(work >> 8) & 0x3f]
^ Spbox[2][(work >> 16) & 0x3f]
^ Spbox[0][(work >> 24) & 0x3f];
work = l ^ key[3];
r ^= Spbox[7][(work) & 0x3f]
^ Spbox[5][(work >> 8) & 0x3f]
^ Spbox[3][(work >> 16) & 0x3f]
^ Spbox[1][(work >> 24) & 0x3f];
left is in aex
right is in ebx
key is in edx
edvances key for next round
uses ecx, esi, and edi
*/
#define DesRound() \
AS2( mov ecx, ebx )\
AS2( mov esi, DWORD PTR [edx] )\
AS2( ror ecx, 4 )\
AS2( xor ecx, esi )\
AS2( and ecx, 0x3f3f3f3f )\
AS2( movzx esi, cl )\
AS2( movzx edi, ch )\
AS2( xor eax, [ebp + esi*4 + 6*256] )\
AS2( shr ecx, 16 )\
AS2( xor eax, [ebp + edi*4 + 4*256] )\
AS2( movzx esi, cl )\
AS2( movzx edi, ch )\
AS2( xor eax, [ebp + esi*4 + 2*256] )\
AS2( mov esi, DWORD PTR [edx + 4] )\
AS2( xor eax, [ebp + edi*4] )\
AS2( mov ecx, ebx )\
AS2( xor ecx, esi )\
AS2( and ecx, 0x3f3f3f3f )\
AS2( movzx esi, cl )\
AS2( movzx edi, ch )\
AS2( xor eax, [ebp + esi*4 + 7*256] )\
AS2( shr ecx, 16 )\
AS2( xor eax, [ebp + edi*4 + 5*256] )\
AS2( movzx esi, cl )\
AS2( movzx edi, ch )\
AS2( xor eax, [ebp + esi*4 + 3*256] )\
AS2( mov esi, DWORD PTR [edx + 8] )\
AS2( xor eax, [ebp + edi*4 + 1*256] )\
AS2( mov ecx, eax )\
AS2( ror ecx, 4 )\
AS2( xor ecx, esi )\
AS2( and ecx, 0x3f3f3f3f )\
AS2( movzx esi, cl )\
AS2( movzx edi, ch )\
AS2( xor ebx, [ebp + esi*4 + 6*256] )\
AS2( shr ecx, 16 )\
AS2( xor ebx, [ebp + edi*4 + 4*256] )\
AS2( movzx esi, cl )\
AS2( movzx edi, ch )\
AS2( xor ebx, [ebp + esi*4 + 2*256] )\
AS2( mov esi, DWORD PTR [edx + 12] )\
AS2( xor ebx, [ebp + edi*4] )\
AS2( mov ecx, eax )\
AS2( xor ecx, esi )\
AS2( and ecx, 0x3f3f3f3f )\
AS2( movzx esi, cl )\
AS2( movzx edi, ch )\
AS2( xor ebx, [ebp + esi*4 + 7*256] )\
AS2( shr ecx, 16 )\
AS2( xor ebx, [ebp + edi*4 + 5*256] )\
AS2( movzx esi, cl )\
AS2( movzx edi, ch )\
AS2( xor ebx, [ebp + esi*4 + 3*256] )\
AS2( add edx, 16 )\
AS2( xor ebx, [ebp + edi*4 + 1*256] )
#ifdef _MSC_VER
__declspec(naked)
#endif
void DES_EDE3::AsmProcess(const byte* in, byte* out, void* box) const
{
#ifdef __GNUC__
#define AS1(x) asm(#x);
#define AS2(x, y) asm(#x ", " #y);
asm(".intel_syntax noprefix");
#define PROLOG() \
AS2( movd mm3, edi ) \
AS2( movd mm4, ebx ) \
AS2( movd mm5, esi ) \
AS2( movd mm6, ebp ) \
AS2( mov edx, DWORD PTR [ebp + 8] ) \
AS2( mov esi, DWORD PTR [ebp + 12] ) \
AS2( mov ebp, DWORD PTR [ebp + 20] )
// ebp restored at end
#define EPILOG() \
AS2( movd edi, mm3 ) \
AS2( movd ebx, mm4 ) \
AS2( movd esi, mm5 ) \
AS1( emms ) \
asm(".att_syntax");
#else
#define AS1(x) __asm x
#define AS2(x, y) __asm x, y
#define PROLOG() \
AS1( push ebp ) \
AS2( mov ebp, esp ) \
AS2( movd mm3, edi ) \
AS2( movd mm4, ebx ) \
AS2( movd mm5, esi ) \
AS2( movd mm6, ebp ) \
AS2( mov esi, DWORD PTR [ebp + 8] ) \
AS2( mov edx, ecx ) \
AS2( mov ebp, DWORD PTR [ebp + 16] )
// ebp restored at end
#define EPILOG() \
AS2( movd edi, mm3 ) \
AS2( movd ebx, mm4 ) \
AS2( movd esi, mm5 ) \
AS2( mov esp, ebp ) \
AS1( pop ebp ) \
AS1( emms ) \
AS1( ret 12 )
#endif
PROLOG()
AS2( movd mm2, edx )
#ifdef OLD_GCC_OFFSET
AS2( add edx, 60 ) // des1 = des1 key
#else
AS2( add edx, 56 ) // des1 = des1 key
#endif
AS2( mov eax, DWORD PTR [esi] )
AS2( mov ebx, DWORD PTR [esi + 4] )
AS1( bswap eax ) // left
AS1( bswap ebx ) // right
AsmIPERM()
DesRound() // 1
DesRound() // 2
DesRound() // 3
DesRound() // 4
DesRound() // 5
DesRound() // 6
DesRound() // 7
DesRound() // 8
// swap left and right
AS2( xchg eax, ebx )
DesRound() // 1
DesRound() // 2
DesRound() // 3
DesRound() // 4
DesRound() // 5
DesRound() // 6
DesRound() // 7
DesRound() // 8
// swap left and right
AS2( xchg eax, ebx )
DesRound() // 1
DesRound() // 2
DesRound() // 3
DesRound() // 4
DesRound() // 5
DesRound() // 6
DesRound() // 7
DesRound() // 8
AsmFPERM()
//end
AS2( movd ebp, mm6 )
// swap and write out
AS1( bswap ebx )
AS1( bswap eax )
#ifdef __GNUC__
AS2( mov esi, DWORD PTR [ebp + 16] ) // outBlock
#else
AS2( mov esi, DWORD PTR [ebp + 12] ) // outBlock
#endif
AS2( mov DWORD PTR [esi], ebx ) // right first
AS2( mov DWORD PTR [esi + 4], eax )
EPILOG()
}
#endif // defined(DO_DES_ASM)
} // namespace

View File

@ -26,10 +26,26 @@
#include "runtime.hpp"
#include "dh.hpp"
#include "asn.hpp"
#include <math.h>
namespace TaoCrypt {
namespace { // locals
unsigned int DiscreteLogWorkFactor(unsigned int n)
{
// assuming discrete log takes about the same time as factoring
if (n<5)
return 0;
else
return (unsigned int)(2.4 * pow((double)n, 1.0/3.0) *
pow(log(double(n)), 2.0/3.0) - 5);
}
} // namespace locals
// Generate a DH Key Pair
void DH::GenerateKeyPair(RandomNumberGenerator& rng, byte* priv, byte* pub)
{
@ -41,7 +57,8 @@ void DH::GenerateKeyPair(RandomNumberGenerator& rng, byte* priv, byte* pub)
// Generate private value
void DH::GeneratePrivate(RandomNumberGenerator& rng, byte* priv)
{
Integer x(rng, Integer::One(), p_ - 1);
Integer x(rng, Integer::One(), mySTL::min(p_ - 1,
Integer::Power2(2*DiscreteLogWorkFactor(p_.BitCount())) ) );
x.Encode(priv, p_.ByteCount());
}
@ -57,11 +74,16 @@ void DH::GeneratePublic(const byte* priv, byte* pub)
// Generate Agreement
void DH::Agree(byte* agree, const byte* priv, const byte* otherPub)
void DH::Agree(byte* agree, const byte* priv, const byte* otherPub, word32
otherSz)
{
const word32 bc(p_.ByteCount());
Integer x(priv, bc);
Integer y(otherPub, bc);
Integer y;
if (otherSz)
y.Decode(otherPub, otherSz);
else
y.Decode(otherPub, bc);
Integer z(a_exp_b_mod_c(y, x, p_));
z.Encode(agree, bc);

View File

@ -39,6 +39,15 @@ HASHwithTransform::HASHwithTransform(word32 digSz, word32 buffSz)
}
void HASHwithTransform::AddLength(word32 len)
{
HashLengthType tmp = loLen_;
if ( (loLen_ += len) < tmp)
hiLen_++; // carry low to high
hiLen_ += SafeRightShift<8*sizeof(HashLengthType)>(len);
}
// Update digest with data of size len, do in blocks
void HASHwithTransform::Update(const byte* data, word32 len)
{
@ -57,6 +66,8 @@ void HASHwithTransform::Update(const byte* data, word32 len)
if (buffLen_ == blockSz) {
ByteReverseIf(local, local, blockSz, getByteOrder());
Transform();
AddLength(blockSz);
buffLen_ = 0;
}
}
}
@ -69,25 +80,29 @@ void HASHwithTransform::Final(byte* hash)
word32 digestSz = getDigestSize();
word32 padSz = getPadSize();
ByteOrder order = getByteOrder();
word32 prePadLen = length_ + buffLen_ * 8; // in bits
AddLength(buffLen_); // before adding pads
HashLengthType preLoLen = GetBitCountLo();
HashLengthType preHiLen = GetBitCountHi();
byte* local = reinterpret_cast<byte*>(buffer_);
local[buffLen_++] = 0x80; // add 1
// pad with zeros
if (buffLen_ > padSz) {
while (buffLen_ < blockSz) local[buffLen_++] = 0;
memset(&local[buffLen_], 0, blockSz - buffLen_);
buffLen_ += blockSz - buffLen_;
ByteReverseIf(local, local, blockSz, order);
Transform();
buffLen_ = 0;
}
while (buffLen_ < padSz) local[buffLen_++] = 0;
memset(&local[buffLen_], 0, padSz - buffLen_);
ByteReverseIf(local, local, blockSz, order);
word32 hiSize = 0; // for future 64 bit length TODO:
memcpy(&local[padSz], order ? &hiSize : &prePadLen, sizeof(prePadLen));
memcpy(&local[padSz+4], order ? &prePadLen : &hiSize, sizeof(prePadLen));
memcpy(&local[padSz], order ? &preHiLen : &preLoLen, sizeof(preLoLen));
memcpy(&local[padSz+4], order ? &preLoLen : &preHiLen, sizeof(preLoLen));
Transform();
ByteReverseIf(digest_, digest_, digestSz, order);

View File

@ -114,7 +114,7 @@ CPP_TYPENAME AllocatorBase<T>::pointer AlignedAllocator<T>::allocate(
assert(IsAlignedOn(p, 16));
return (T*)p;
}
return new (tc) T[n];
return NEW_TC T[n];
}
@ -555,7 +555,7 @@ static word AtomicInverseModPower2(word A)
for (unsigned i=3; i<WORD_BITS; i*=2)
R = R*(2-R*A);
assert(R*A==1);
assert(word(R*A)==1);
return R;
}
@ -568,21 +568,21 @@ public:
static word Add(word *C, const word *A, const word *B, unsigned int N);
static word Subtract(word *C, const word *A, const word*B, unsigned int N);
static inline void Multiply2(word *C, const word *A, const word *B);
static inline word Multiply2Add(word *C, const word *A, const word *B);
static void Multiply2(word *C, const word *A, const word *B);
static word Multiply2Add(word *C, const word *A, const word *B);
static void Multiply4(word *C, const word *A, const word *B);
static void Multiply8(word *C, const word *A, const word *B);
static inline unsigned int MultiplyRecursionLimit() {return 8;}
static unsigned int MultiplyRecursionLimit() {return 8;}
static inline void Multiply2Bottom(word *C, const word *A, const word *B);
static void Multiply2Bottom(word *C, const word *A, const word *B);
static void Multiply4Bottom(word *C, const word *A, const word *B);
static void Multiply8Bottom(word *C, const word *A, const word *B);
static inline unsigned int MultiplyBottomRecursionLimit() {return 8;}
static unsigned int MultiplyBottomRecursionLimit() {return 8;}
static void Square2(word *R, const word *A);
static void Square4(word *R, const word *A);
static void Square8(word *R, const word *A) {assert(false);}
static inline unsigned int SquareRecursionLimit() {return 4;}
static unsigned int SquareRecursionLimit() {return 4;}
};
word Portable::Add(word *C, const word *A, const word *B, unsigned int N)
@ -668,7 +668,7 @@ void Portable::Multiply2(word *C, const word *A, const word *B)
C[3] = t.GetHighHalf();
}
inline void Portable::Multiply2Bottom(word *C, const word *A, const word *B)
void Portable::Multiply2Bottom(word *C, const word *A, const word *B)
{
DWord t = DWord::Multiply(A[0], B[0]);
C[0] = t.GetLowHalf();
@ -2714,7 +2714,7 @@ static Integer* zero = 0;
const Integer &Integer::Zero()
{
if (!zero)
zero = new (tc) Integer;
zero = NEW_TC Integer;
return *zero;
}
@ -2724,7 +2724,7 @@ static Integer* one = 0;
const Integer &Integer::One()
{
if (!one)
one = new (tc) Integer(1,2);
one = NEW_TC Integer(1,2);
return *one;
}

View File

@ -0,0 +1,38 @@
# quick and dirty build file for testing different MSDEVs
setlocal
set myFLAGS= /I../include /I../../mySTL /c /W3 /G6 /O2
#set myFLAGS= /I../include /I../../mySTL /c /W3 /O1
cl %myFLAGS% aes.cpp
cl %myFLAGS% aestables.cpp
cl %myFLAGS% algebra.cpp
cl %myFLAGS% arc4.cpp
cl %myFLAGS% asn.cpp
cl %myFLAGS% bftables.cpp
cl %myFLAGS% blowfish.cpp
cl %myFLAGS% coding.cpp
cl %myFLAGS% des.cpp
cl %myFLAGS% dh.cpp
cl %myFLAGS% dsa.cpp
cl %myFLAGS% file.cpp
cl %myFLAGS% hash.cpp
cl %myFLAGS% integer.cpp
cl %myFLAGS% md2.cpp
cl %myFLAGS% md5.cpp
cl %myFLAGS% misc.cpp
cl %myFLAGS% random.cpp
cl %myFLAGS% ripemd.cpp
cl %myFLAGS% rsa.cpp
cl %myFLAGS% sha.cpp
cl %myFLAGS% template_instnt.cpp
cl %myFLAGS% tftables.cpp
cl %myFLAGS% twofish.cpp
link.exe -lib /out:taocrypt.lib aes.obj aestables.obj algebra.obj arc4.obj asn.obj bftables.obj blowfish.obj coding.obj des.obj dh.obj dsa.obj file.obj hash.obj integer.obj md2.obj md5.obj misc.obj random.obj ripemd.obj rsa.obj sha.obj template_instnt.obj tftables.obj twofish.obj

View File

@ -26,6 +26,11 @@
#include "md5.hpp"
#include "algorithm.hpp" // mySTL::swap
#if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
#define DO_MD5_ASM
#endif
namespace TaoCrypt {
void MD5::Init()
@ -36,7 +41,8 @@ void MD5::Init()
digest_[3] = 0x10325476L;
buffLen_ = 0;
length_ = 0;
loLen_ = 0;
hiLen_ = 0;
}
@ -44,7 +50,8 @@ MD5::MD5(const MD5& that) : HASHwithTransform(DIGEST_SIZE / sizeof(word32),
BLOCK_SIZE)
{
buffLen_ = that.buffLen_;
length_ = that.length_;
loLen_ = that.loLen_;
hiLen_ = that.hiLen_;
memcpy(digest_, that.digest_, DIGEST_SIZE);
memcpy(buffer_, that.buffer_, BLOCK_SIZE);
@ -61,7 +68,8 @@ MD5& MD5::operator= (const MD5& that)
void MD5::Swap(MD5& other)
{
mySTL::swap(length_, other.length_);
mySTL::swap(loLen_, other.loLen_);
mySTL::swap(hiLen_, other.hiLen_);
mySTL::swap(buffLen_, other.buffLen_);
memcpy(digest_, other.digest_, DIGEST_SIZE);
@ -69,6 +77,335 @@ void MD5::Swap(MD5& other)
}
// Update digest with data of size len, do in blocks
void MD5::Update(const byte* data, word32 len)
{
byte* local = (byte*)buffer_;
// remove buffered data if possible
if (buffLen_) {
word32 add = min(len, BLOCK_SIZE - buffLen_);
memcpy(&local[buffLen_], data, add);
buffLen_ += add;
data += add;
len -= add;
if (buffLen_ == BLOCK_SIZE) {
ByteReverseIf(local, local, BLOCK_SIZE, LittleEndianOrder);
Transform();
AddLength(BLOCK_SIZE);
buffLen_ = 0;
}
}
// do block size transforms or all at once for asm
if (buffLen_ == 0) {
#ifndef DO_MD5_ASM
while (len >= BLOCK_SIZE) {
memcpy(&local[0], data, BLOCK_SIZE);
data += BLOCK_SIZE;
len -= BLOCK_SIZE;
ByteReverseIf(local, local, BLOCK_SIZE, LittleEndianOrder);
Transform();
AddLength(BLOCK_SIZE);
}
#else
word32 times = len / BLOCK_SIZE;
if (times) {
AsmTransform(data, times);
const word32 add = BLOCK_SIZE * times;
AddLength(add);
len -= add;
data += add;
}
#endif
}
// cache any data left
if (len) {
memcpy(&local[buffLen_], data, len);
buffLen_ += len;
}
}
#ifdef DO_MD5_ASM
/*
// w = rotlFixed(w + f(x, y, z) + index[edi] + data, s) + x
#define ASMMD5STEP(f, w, x, y, z, index, data, s) \
f(x, y, z) \
AS2( mov ebp, [edi + index * 4] ) \
AS2( lea w, [esi + w + data] ) \
AS2( add w, ebp ) \
AS2( rol w, s ) \
AS2( add w, x )
// F1(x, y, z) (z ^ (x & (y ^ z)))
// place in esi
#define ASMF1(x, y, z) \
AS2( mov esi, y ) \
AS2( xor esi, z ) \
AS2( and esi, x ) \
AS2( xor esi, z )
#define ASMF2(x, y, z) ASMF1(z, x, y)
// F3(x ^ y ^ z)
// place in esi
#define ASMF3(x, y, z) \
AS2( mov esi, x ) \
AS2( xor esi, y ) \
AS2( xor esi, z )
// F4(x, y, z) (y ^ (x | ~z))
// place in esi
#define ASMF4(x, y, z) \
AS2( mov esi, z ) \
AS1( not esi ) \
AS2( or esi, x ) \
AS2( xor esi, y )
*/
// combine above ASMMD5STEP(f w/ each f ASMF1 - F4
// esi already set up, after using set for next round
// ebp already set up, set up using next round index
#define MD5STEP1(w, x, y, z, index, data, s) \
AS2( xor esi, z ) \
AS2( and esi, x ) \
AS2( lea w, [ebp + w + data] ) \
AS2( xor esi, z ) \
AS2( add w, esi ) \
AS2( mov esi, x ) \
AS2( rol w, s ) \
AS2( mov ebp, [edi + index * 4] ) \
AS2( add w, x )
#define MD5STEP2(w, x, y, z, index, data, s) \
AS2( xor esi, x ) \
AS2( and esi, z ) \
AS2( lea w, [ebp + w + data] ) \
AS2( xor esi, y ) \
AS2( add w, esi ) \
AS2( mov esi, x ) \
AS2( rol w, s ) \
AS2( mov ebp, [edi + index * 4] ) \
AS2( add w, x )
#define MD5STEP3(w, x, y, z, index, data, s) \
AS2( xor esi, z ) \
AS2( lea w, [ebp + w + data] ) \
AS2( xor esi, x ) \
AS2( add w, esi ) \
AS2( mov esi, x ) \
AS2( rol w, s ) \
AS2( mov ebp, [edi + index * 4] ) \
AS2( add w, x )
#define MD5STEP4(w, x, y, z, index, data, s) \
AS2( or esi, x ) \
AS2( lea w, [ebp + w + data] ) \
AS2( xor esi, y ) \
AS2( add w, esi ) \
AS2( mov esi, y ) \
AS2( rol w, s ) \
AS1( not esi ) \
AS2( mov ebp, [edi + index * 4] ) \
AS2( add w, x )
#ifdef _MSC_VER
__declspec(naked)
#endif
void MD5::AsmTransform(const byte* data, word32 times)
{
#ifdef __GNUC__
#define AS1(x) asm(#x);
#define AS2(x, y) asm(#x ", " #y);
#define PROLOG() \
asm(".intel_syntax noprefix"); \
AS2( movd mm3, edi ) \
AS2( movd mm4, ebx ) \
AS2( movd mm5, esi ) \
AS2( movd mm6, ebp ) \
AS2( mov ecx, DWORD PTR [ebp + 8] ) \
AS2( mov edi, DWORD PTR [ebp + 12] ) \
AS2( mov eax, DWORD PTR [ebp + 16] )
#define EPILOG() \
AS2( movd ebp, mm6 ) \
AS2( movd esi, mm5 ) \
AS2( movd ebx, mm4 ) \
AS2( mov esp, ebp ) \
AS2( movd edi, mm3 ) \
AS1( emms ) \
asm(".att_syntax");
#else
#define AS1(x) __asm x
#define AS2(x, y) __asm x, y
#define PROLOG() \
AS1( push ebp ) \
AS2( mov ebp, esp ) \
AS2( movd mm3, edi ) \
AS2( movd mm4, ebx ) \
AS2( movd mm5, esi ) \
AS2( movd mm6, ebp ) \
AS2( mov edi, DWORD PTR [ebp + 8] ) \
AS2( mov eax, DWORD PTR [ebp + 12] )
#define EPILOG() \
AS2( movd ebp, mm6 ) \
AS2( movd esi, mm5 ) \
AS2( movd ebx, mm4 ) \
AS2( movd edi, mm3 ) \
AS2( mov esp, ebp ) \
AS1( pop ebp ) \
AS1( emms ) \
AS1( ret 8 )
#endif
PROLOG()
AS2( mov esi, ecx )
#ifdef OLD_GCC_OFFSET
AS2( add esi, 20 ) // digest_[0]
#else
AS2( add esi, 16 ) // digest_[0]
#endif
AS2( movd mm2, eax ) // store times_
AS2( movd mm1, esi ) // store digest_
AS2( mov eax, [esi] ) // a
AS2( mov ebx, [esi + 4] ) // b
AS2( mov ecx, [esi + 8] ) // c
AS2( mov edx, [esi + 12] ) // d
AS1(loopStart:)
// set up
AS2( mov esi, ecx )
AS2( mov ebp, [edi] )
MD5STEP1( eax, ebx, ecx, edx, 1, 0xd76aa478, 7)
MD5STEP1( edx, eax, ebx, ecx, 2, 0xe8c7b756, 12)
MD5STEP1( ecx, edx, eax, ebx, 3, 0x242070db, 17)
MD5STEP1( ebx, ecx, edx, eax, 4, 0xc1bdceee, 22)
MD5STEP1( eax, ebx, ecx, edx, 5, 0xf57c0faf, 7)
MD5STEP1( edx, eax, ebx, ecx, 6, 0x4787c62a, 12)
MD5STEP1( ecx, edx, eax, ebx, 7, 0xa8304613, 17)
MD5STEP1( ebx, ecx, edx, eax, 8, 0xfd469501, 22)
MD5STEP1( eax, ebx, ecx, edx, 9, 0x698098d8, 7)
MD5STEP1( edx, eax, ebx, ecx, 10, 0x8b44f7af, 12)
MD5STEP1( ecx, edx, eax, ebx, 11, 0xffff5bb1, 17)
MD5STEP1( ebx, ecx, edx, eax, 12, 0x895cd7be, 22)
MD5STEP1( eax, ebx, ecx, edx, 13, 0x6b901122, 7)
MD5STEP1( edx, eax, ebx, ecx, 14, 0xfd987193, 12)
MD5STEP1( ecx, edx, eax, ebx, 15, 0xa679438e, 17)
MD5STEP1( ebx, ecx, edx, eax, 1, 0x49b40821, 22)
MD5STEP2( eax, ebx, ecx, edx, 6, 0xf61e2562, 5)
MD5STEP2( edx, eax, ebx, ecx, 11, 0xc040b340, 9)
MD5STEP2( ecx, edx, eax, ebx, 0, 0x265e5a51, 14)
MD5STEP2( ebx, ecx, edx, eax, 5, 0xe9b6c7aa, 20)
MD5STEP2( eax, ebx, ecx, edx, 10, 0xd62f105d, 5)
MD5STEP2( edx, eax, ebx, ecx, 15, 0x02441453, 9)
MD5STEP2( ecx, edx, eax, ebx, 4, 0xd8a1e681, 14)
MD5STEP2( ebx, ecx, edx, eax, 9, 0xe7d3fbc8, 20)
MD5STEP2( eax, ebx, ecx, edx, 14, 0x21e1cde6, 5)
MD5STEP2( edx, eax, ebx, ecx, 3, 0xc33707d6, 9)
MD5STEP2( ecx, edx, eax, ebx, 8, 0xf4d50d87, 14)
MD5STEP2( ebx, ecx, edx, eax, 13, 0x455a14ed, 20)
MD5STEP2( eax, ebx, ecx, edx, 2, 0xa9e3e905, 5)
MD5STEP2( edx, eax, ebx, ecx, 7, 0xfcefa3f8, 9)
MD5STEP2( ecx, edx, eax, ebx, 12, 0x676f02d9, 14)
MD5STEP2( ebx, ecx, edx, eax, 5, 0x8d2a4c8a, 20)
MD5STEP3( eax, ebx, ecx, edx, 8, 0xfffa3942, 4)
MD5STEP3( edx, eax, ebx, ecx, 11, 0x8771f681, 11)
MD5STEP3( ecx, edx, eax, ebx, 14, 0x6d9d6122, 16)
MD5STEP3( ebx, ecx, edx, eax, 1, 0xfde5380c, 23)
MD5STEP3( eax, ebx, ecx, edx, 4, 0xa4beea44, 4)
MD5STEP3( edx, eax, ebx, ecx, 7, 0x4bdecfa9, 11)
MD5STEP3( ecx, edx, eax, ebx, 10, 0xf6bb4b60, 16)
MD5STEP3( ebx, ecx, edx, eax, 13, 0xbebfbc70, 23)
MD5STEP3( eax, ebx, ecx, edx, 0, 0x289b7ec6, 4)
MD5STEP3( edx, eax, ebx, ecx, 3, 0xeaa127fa, 11)
MD5STEP3( ecx, edx, eax, ebx, 6, 0xd4ef3085, 16)
MD5STEP3( ebx, ecx, edx, eax, 9, 0x04881d05, 23)
MD5STEP3( eax, ebx, ecx, edx, 12, 0xd9d4d039, 4)
MD5STEP3( edx, eax, ebx, ecx, 15, 0xe6db99e5, 11)
MD5STEP3( ecx, edx, eax, ebx, 2, 0x1fa27cf8, 16)
MD5STEP3( ebx, ecx, edx, eax, 0, 0xc4ac5665, 23)
// setup
AS2( mov esi, edx )
AS1( not esi )
MD5STEP4( eax, ebx, ecx, edx, 7, 0xf4292244, 6)
MD5STEP4( edx, eax, ebx, ecx, 14, 0x432aff97, 10)
MD5STEP4( ecx, edx, eax, ebx, 5, 0xab9423a7, 15)
MD5STEP4( ebx, ecx, edx, eax, 12, 0xfc93a039, 21)
MD5STEP4( eax, ebx, ecx, edx, 3, 0x655b59c3, 6)
MD5STEP4( edx, eax, ebx, ecx, 10, 0x8f0ccc92, 10)
MD5STEP4( ecx, edx, eax, ebx, 1, 0xffeff47d, 15)
MD5STEP4( ebx, ecx, edx, eax, 8, 0x85845dd1, 21)
MD5STEP4( eax, ebx, ecx, edx, 15, 0x6fa87e4f, 6)
MD5STEP4( edx, eax, ebx, ecx, 6, 0xfe2ce6e0, 10)
MD5STEP4( ecx, edx, eax, ebx, 13, 0xa3014314, 15)
MD5STEP4( ebx, ecx, edx, eax, 4, 0x4e0811a1, 21)
MD5STEP4( eax, ebx, ecx, edx, 11, 0xf7537e82, 6)
MD5STEP4( edx, eax, ebx, ecx, 2, 0xbd3af235, 10)
MD5STEP4( ecx, edx, eax, ebx, 9, 0x2ad7d2bb, 15)
MD5STEP4( ebx, ecx, edx, eax, 9, 0xeb86d391, 21)
AS2( movd esi, mm1 ) // digest_
AS2( add [esi], eax ) // write out
AS2( add [esi + 4], ebx )
AS2( add [esi + 8], ecx )
AS2( add [esi + 12], edx )
AS2( add edi, 64 )
AS2( mov eax, [esi] )
AS2( mov ebx, [esi + 4] )
AS2( mov ecx, [esi + 8] )
AS2( mov edx, [esi + 12] )
AS2( movd ebp, mm2 ) // times
AS1( dec ebp )
AS2( movd mm2, ebp )
AS1( jnz loopStart )
EPILOG()
}
#endif // DO_MD5_ASM
void MD5::Transform()
{
#define F1(x, y, z) (z ^ (x & (y ^ z)))
@ -161,10 +498,8 @@ void MD5::Transform()
// Wipe variables
a = b = c = d = 0;
buffLen_ = 0;
length_ += 512;
}
} // namespace

View File

@ -25,27 +25,20 @@
#include "runtime.hpp"
#include "misc.hpp"
#ifdef YASSL_PURE_C
void* operator new(size_t sz, TaoCrypt::new_t)
{
#ifdef YASSL_PURE_C
void* ptr = malloc(sz ? sz : 1);
if (!ptr) abort();
return ptr;
#else
return ::operator new(sz);
#endif
}
void operator delete(void* ptr, TaoCrypt::new_t)
{
#ifdef YASSL_PURE_C
if (ptr) free(ptr);
#else
::operator delete(ptr);
#endif
}
@ -75,9 +68,15 @@ void operator delete[](void* ptr);
namespace TaoCrypt {
new_t tc; // for library new
}
#endif // YASSL_PURE_C
namespace TaoCrypt {
inline void XorWords(word* r, const word* a, unsigned int n)
{

View File

@ -26,6 +26,8 @@
#include "runtime.hpp"
#include "random.hpp"
#include <string.h>
#if defined(_WIN32)
#define _WIN32_WINNT 0x0400
@ -52,6 +54,7 @@ RandomNumberGenerator::RandomNumberGenerator()
// place a generated block in output
void RandomNumberGenerator::GenerateBlock(byte* output, word32 sz)
{
memset(output, 0, sz);
cipher_.Process(output, output, sz);
}
@ -94,8 +97,7 @@ void OS_Seed::GenerateSeed(byte* output, word32 sz)
OS_Seed::OS_Seed()
{
fd_ = open("/dev/urandom",O_RDONLY);
if (fd_ == -1)
{
if (fd_ == -1) {
fd_ = open("/dev/random",O_RDONLY);
if (fd_ == -1)
error_.SetError(OPEN_RAN_E);

View File

@ -26,6 +26,12 @@
#include "ripemd.hpp"
#include "algorithm.hpp" // mySTL::swap
#if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
#define DO_RIPEMD_ASM
#endif
namespace TaoCrypt {
void RIPEMD160::Init()
@ -37,7 +43,8 @@ void RIPEMD160::Init()
digest_[4] = 0xc3d2e1f0L;
buffLen_ = 0;
length_ = 0;
loLen_ = 0;
hiLen_ = 0;
}
@ -45,7 +52,8 @@ RIPEMD160::RIPEMD160(const RIPEMD160& that)
: HASHwithTransform(DIGEST_SIZE / sizeof(word32), BLOCK_SIZE)
{
buffLen_ = that.buffLen_;
length_ = that.length_;
loLen_ = that.loLen_;
hiLen_ = that.hiLen_;
memcpy(digest_, that.digest_, DIGEST_SIZE);
memcpy(buffer_, that.buffer_, BLOCK_SIZE);
@ -63,7 +71,8 @@ RIPEMD160& RIPEMD160::operator= (const RIPEMD160& that)
void RIPEMD160::Swap(RIPEMD160& other)
{
mySTL::swap(length_, other.length_);
mySTL::swap(loLen_, other.loLen_);
mySTL::swap(hiLen_, other.hiLen_);
mySTL::swap(buffLen_, other.buffLen_);
memcpy(digest_, other.digest_, DIGEST_SIZE);
@ -71,6 +80,61 @@ void RIPEMD160::Swap(RIPEMD160& other)
}
// Update digest with data of size len, do in blocks
void RIPEMD160::Update(const byte* data, word32 len)
{
byte* local = (byte*)buffer_;
// remove buffered data if possible
if (buffLen_) {
word32 add = min(len, BLOCK_SIZE - buffLen_);
memcpy(&local[buffLen_], data, add);
buffLen_ += add;
data += add;
len -= add;
if (buffLen_ == BLOCK_SIZE) {
ByteReverseIf(local, local, BLOCK_SIZE, LittleEndianOrder);
Transform();
AddLength(BLOCK_SIZE);
buffLen_ = 0;
}
}
// do block size transforms or all at once for asm
if (buffLen_ == 0) {
#ifndef DO_RIPEMD_ASM
while (len >= BLOCK_SIZE) {
memcpy(&local[0], data, BLOCK_SIZE);
data += BLOCK_SIZE;
len -= BLOCK_SIZE;
ByteReverseIf(local, local, BLOCK_SIZE, LittleEndianOrder);
Transform();
AddLength(BLOCK_SIZE);
}
#else
word32 times = len / BLOCK_SIZE;
if (times) {
AsmTransform(data, times);
const word32 add = BLOCK_SIZE * times;
AddLength(add);
len -= add;
data += add;
}
#endif
}
// cache any data left
if (len) {
memcpy(&local[buffLen_], data, len);
buffLen_ += len;
}
}
// for all
#define F(x, y, z) (x ^ y ^ z)
#define G(x, y, z) (z ^ (x & (y^z)))
@ -79,14 +143,14 @@ void RIPEMD160::Swap(RIPEMD160& other)
#define J(x, y, z) (x ^ (y | ~z))
#define k0 0
#define k1 0x5a827999UL
#define k2 0x6ed9eba1UL
#define k3 0x8f1bbcdcUL
#define k4 0xa953fd4eUL
#define k5 0x50a28be6UL
#define k6 0x5c4dd124UL
#define k7 0x6d703ef3UL
#define k8 0x7a6d76e9UL
#define k1 0x5a827999
#define k2 0x6ed9eba1
#define k3 0x8f1bbcdc
#define k4 0xa953fd4e
#define k5 0x50a28be6
#define k6 0x5c4dd124
#define k7 0x6d703ef3
#define k8 0x7a6d76e9
#define k9 0
// for 160 and 320
@ -281,10 +345,495 @@ void RIPEMD160::Transform()
digest_[3] = digest_[4] + a1 + b2;
digest_[4] = digest_[0] + b1 + c2;
digest_[0] = c1;
buffLen_ = 0;
length_ += 512;
}
#ifdef DO_RIPEMD_ASM
/*
// F(x ^ y ^ z)
// place in esi
#define ASMF(x, y, z) \
AS2( mov esi, x ) \
AS2( xor esi, y ) \
AS2( xor esi, z )
// G(z ^ (x & (y^z)))
// place in esi
#define ASMG(x, y, z) \
AS2( mov esi, z ) \
AS2( xor esi, y ) \
AS2( and esi, x ) \
AS2( xor esi, z )
// H(z ^ (x | ~y))
// place in esi
#define ASMH(x, y, z) \
AS2( mov esi, y ) \
AS1( not esi ) \
AS2( or esi, x ) \
AS2( xor esi, z )
// I(y ^ (z & (x^y)))
// place in esi
#define ASMI(x, y, z) \
AS2( mov esi, y ) \
AS2( xor esi, x ) \
AS2( and esi, z ) \
AS2( xor esi, y )
// J(x ^ (y | ~z)))
// place in esi
#define ASMJ(x, y, z) \
AS2( mov esi, z ) \
AS1( not esi ) \
AS2( or esi, y ) \
AS2( xor esi, x )
// for 160 and 320
// #define ASMSubround(f, a, b, c, d, e, i, s, k)
// a += f(b, c, d) + data[i] + k;
// a = rotlFixed((word32)a, s) + e;
// c = rotlFixed((word32)c, 10U)
#define ASMSubround(f, a, b, c, d, e, index, s, k) \
// a += f(b, c, d) + data[i] + k \
AS2( mov esp, [edi + index * 4] ) \
f(b, c, d) \
AS2( add esi, k ) \
AS2( add esi, esp ) \
AS2( add a, esi ) \
// a = rotlFixed((word32)a, s) + e \
AS2( rol a, s ) \
AS2( rol c, 10 ) \
// c = rotlFixed((word32)c, 10U) \
AS2( add a, e )
*/
// combine F into subround w/ setup
// esi already has c, setup for next round when done
// esp already has edi[index], setup for next round when done
#define ASMSubroundF(a, b, c, d, e, index, s) \
/* a += (b ^ c ^ d) + data[i] + k */ \
AS2( xor esi, b ) \
AS2( add a, [edi + index * 4] ) \
AS2( xor esi, d ) \
AS2( add a, esi ) \
/* a = rotlFixed((word32)a, s) + e */ \
AS2( mov esi, b ) \
AS2( rol a, s ) \
/* c = rotlFixed((word32)c, 10U) */ \
AS2( rol c, 10 ) \
AS2( add a, e )
// combine G into subround w/ setup
// esi already has c, setup for next round when done
// esp already has edi[index], setup for next round when done
#define ASMSubroundG(a, b, c, d, e, index, s, k) \
/* a += (d ^ (b & (c^d))) + data[i] + k */ \
AS2( xor esi, d ) \
AS2( and esi, b ) \
AS2( add a, [edi + index * 4] ) \
AS2( xor esi, d ) \
AS2( lea a, [esi + a + k] ) \
/* a = rotlFixed((word32)a, s) + e */ \
AS2( mov esi, b ) \
AS2( rol a, s ) \
/* c = rotlFixed((word32)c, 10U) */ \
AS2( rol c, 10 ) \
AS2( add a, e )
// combine H into subround w/ setup
// esi already has c, setup for next round when done
// esp already has edi[index], setup for next round when done
#define ASMSubroundH(a, b, c, d, e, index, s, k) \
/* a += (d ^ (b | ~c)) + data[i] + k */ \
AS1( not esi ) \
AS2( or esi, b ) \
AS2( add a, [edi + index * 4] ) \
AS2( xor esi, d ) \
AS2( lea a, [esi + a + k] ) \
/* a = rotlFixed((word32)a, s) + e */ \
AS2( mov esi, b ) \
AS2( rol a, s ) \
/* c = rotlFixed((word32)c, 10U) */ \
AS2( rol c, 10 ) \
AS2( add a, e )
// combine I into subround w/ setup
// esi already has c, setup for next round when done
// esp already has edi[index], setup for next round when done
#define ASMSubroundI(a, b, c, d, e, index, s, k) \
/* a += (c ^ (d & (b^c))) + data[i] + k */ \
AS2( xor esi, b ) \
AS2( and esi, d ) \
AS2( add a, [edi + index * 4] ) \
AS2( xor esi, c ) \
AS2( lea a, [esi + a + k] ) \
/* a = rotlFixed((word32)a, s) + e */ \
AS2( mov esi, b ) \
AS2( rol a, s ) \
/* c = rotlFixed((word32)c, 10U) */ \
AS2( rol c, 10 ) \
AS2( add a, e )
// combine J into subround w/ setup
// esi already has d, setup for next round when done
// esp already has edi[index], setup for next round when done
#define ASMSubroundJ(a, b, c, d, e, index, s, k) \
/* a += (b ^ (c | ~d))) + data[i] + k */ \
AS1( not esi ) \
AS2( or esi, c ) \
/* c = rotlFixed((word32)c, 10U) */ \
AS2( add a, [edi + index * 4] ) \
AS2( xor esi, b ) \
AS2( rol c, 10 ) \
AS2( lea a, [esi + a + k] ) \
/* a = rotlFixed((word32)a, s) + e */ \
AS2( rol a, s ) \
AS2( mov esi, c ) \
AS2( add a, e )
#ifdef _MSC_VER
__declspec(naked)
#endif
void RIPEMD160::AsmTransform(const byte* data, word32 times)
{
#ifdef __GNUC__
#define AS1(x) asm(#x);
#define AS2(x, y) asm(#x ", " #y);
#define PROLOG() \
asm(".intel_syntax noprefix"); \
AS2( movd mm3, edi ) \
AS2( movd mm4, ebx ) \
AS2( movd mm5, esi ) \
AS2( movd mm6, ebp ) \
AS2( mov ecx, DWORD PTR [ebp + 8] ) \
AS2( mov edi, DWORD PTR [ebp + 12] ) \
AS2( mov edx, DWORD PTR [ebp + 16] )
#define EPILOG() \
AS2( movd ebp, mm6 ) \
AS2( movd esi, mm5 ) \
AS2( movd ebx, mm4 ) \
AS2( mov esp, ebp ) \
AS2( movd edi, mm3 ) \
AS1( emms ) \
asm(".att_syntax");
#else
#define AS1(x) __asm x
#define AS2(x, y) __asm x, y
#define PROLOG() \
AS1( push ebp ) \
AS2( mov ebp, esp ) \
AS2( movd mm3, edi ) \
AS2( movd mm4, ebx ) \
AS2( movd mm5, esi ) \
AS2( movd mm6, ebp ) \
AS2( mov edi, DWORD PTR [ebp + 8] ) \
AS2( mov edx, DWORD PTR [ebp + 12] )
#define EPILOG() \
AS2( movd ebp, mm6 ) \
AS2( movd esi, mm5 ) \
AS2( movd ebx, mm4 ) \
AS2( movd edi, mm3 ) \
AS2( mov esp, ebp ) \
AS1( pop ebp ) \
AS1( emms ) \
AS1( ret 8 )
#endif
PROLOG()
#ifdef OLD_GCC_OFFSET
AS2( lea esi, [ecx + 20] ) // digest_[0]
#else
AS2( lea esi, [ecx + 16] ) // digest_[0]
#endif
AS2( sub esp, 24 ) // make room for tmp a1 - e1
AS2( movd mm1, esi ) // store digest_
AS1( loopStart: )
AS2( movd mm2, edx ) // store times_
AS2( mov eax, [esi] ) // a1
AS2( mov ebx, [esi + 4] ) // b1
AS2( mov ecx, [esi + 8] ) // c1
AS2( mov edx, [esi + 12] ) // d1
AS2( mov ebp, [esi + 16] ) // e1
// setup
AS2( mov esi, ecx )
ASMSubroundF( eax, ebx, ecx, edx, ebp, 0, 11)
ASMSubroundF( ebp, eax, ebx, ecx, edx, 1, 14)
ASMSubroundF( edx, ebp, eax, ebx, ecx, 2, 15)
ASMSubroundF( ecx, edx, ebp, eax, ebx, 3, 12)
ASMSubroundF( ebx, ecx, edx, ebp, eax, 4, 5)
ASMSubroundF( eax, ebx, ecx, edx, ebp, 5, 8)
ASMSubroundF( ebp, eax, ebx, ecx, edx, 6, 7)
ASMSubroundF( edx, ebp, eax, ebx, ecx, 7, 9)
ASMSubroundF( ecx, edx, ebp, eax, ebx, 8, 11)
ASMSubroundF( ebx, ecx, edx, ebp, eax, 9, 13)
ASMSubroundF( eax, ebx, ecx, edx, ebp, 10, 14)
ASMSubroundF( ebp, eax, ebx, ecx, edx, 11, 15)
ASMSubroundF( edx, ebp, eax, ebx, ecx, 12, 6)
ASMSubroundF( ecx, edx, ebp, eax, ebx, 13, 7)
ASMSubroundF( ebx, ecx, edx, ebp, eax, 14, 9)
ASMSubroundF( eax, ebx, ecx, edx, ebp, 15, 8)
ASMSubroundG( ebp, eax, ebx, ecx, edx, 7, 7, k1)
ASMSubroundG( edx, ebp, eax, ebx, ecx, 4, 6, k1)
ASMSubroundG( ecx, edx, ebp, eax, ebx, 13, 8, k1)
ASMSubroundG( ebx, ecx, edx, ebp, eax, 1, 13, k1)
ASMSubroundG( eax, ebx, ecx, edx, ebp, 10, 11, k1)
ASMSubroundG( ebp, eax, ebx, ecx, edx, 6, 9, k1)
ASMSubroundG( edx, ebp, eax, ebx, ecx, 15, 7, k1)
ASMSubroundG( ecx, edx, ebp, eax, ebx, 3, 15, k1)
ASMSubroundG( ebx, ecx, edx, ebp, eax, 12, 7, k1)
ASMSubroundG( eax, ebx, ecx, edx, ebp, 0, 12, k1)
ASMSubroundG( ebp, eax, ebx, ecx, edx, 9, 15, k1)
ASMSubroundG( edx, ebp, eax, ebx, ecx, 5, 9, k1)
ASMSubroundG( ecx, edx, ebp, eax, ebx, 2, 11, k1)
ASMSubroundG( ebx, ecx, edx, ebp, eax, 14, 7, k1)
ASMSubroundG( eax, ebx, ecx, edx, ebp, 11, 13, k1)
ASMSubroundG( ebp, eax, ebx, ecx, edx, 8, 12, k1)
ASMSubroundH( edx, ebp, eax, ebx, ecx, 3, 11, k2)
ASMSubroundH( ecx, edx, ebp, eax, ebx, 10, 13, k2)
ASMSubroundH( ebx, ecx, edx, ebp, eax, 14, 6, k2)
ASMSubroundH( eax, ebx, ecx, edx, ebp, 4, 7, k2)
ASMSubroundH( ebp, eax, ebx, ecx, edx, 9, 14, k2)
ASMSubroundH( edx, ebp, eax, ebx, ecx, 15, 9, k2)
ASMSubroundH( ecx, edx, ebp, eax, ebx, 8, 13, k2)
ASMSubroundH( ebx, ecx, edx, ebp, eax, 1, 15, k2)
ASMSubroundH( eax, ebx, ecx, edx, ebp, 2, 14, k2)
ASMSubroundH( ebp, eax, ebx, ecx, edx, 7, 8, k2)
ASMSubroundH( edx, ebp, eax, ebx, ecx, 0, 13, k2)
ASMSubroundH( ecx, edx, ebp, eax, ebx, 6, 6, k2)
ASMSubroundH( ebx, ecx, edx, ebp, eax, 13, 5, k2)
ASMSubroundH( eax, ebx, ecx, edx, ebp, 11, 12, k2)
ASMSubroundH( ebp, eax, ebx, ecx, edx, 5, 7, k2)
ASMSubroundH( edx, ebp, eax, ebx, ecx, 12, 5, k2)
ASMSubroundI( ecx, edx, ebp, eax, ebx, 1, 11, k3)
ASMSubroundI( ebx, ecx, edx, ebp, eax, 9, 12, k3)
ASMSubroundI( eax, ebx, ecx, edx, ebp, 11, 14, k3)
ASMSubroundI( ebp, eax, ebx, ecx, edx, 10, 15, k3)
ASMSubroundI( edx, ebp, eax, ebx, ecx, 0, 14, k3)
ASMSubroundI( ecx, edx, ebp, eax, ebx, 8, 15, k3)
ASMSubroundI( ebx, ecx, edx, ebp, eax, 12, 9, k3)
ASMSubroundI( eax, ebx, ecx, edx, ebp, 4, 8, k3)
ASMSubroundI( ebp, eax, ebx, ecx, edx, 13, 9, k3)
ASMSubroundI( edx, ebp, eax, ebx, ecx, 3, 14, k3)
ASMSubroundI( ecx, edx, ebp, eax, ebx, 7, 5, k3)
ASMSubroundI( ebx, ecx, edx, ebp, eax, 15, 6, k3)
ASMSubroundI( eax, ebx, ecx, edx, ebp, 14, 8, k3)
ASMSubroundI( ebp, eax, ebx, ecx, edx, 5, 6, k3)
ASMSubroundI( edx, ebp, eax, ebx, ecx, 6, 5, k3)
ASMSubroundI( ecx, edx, ebp, eax, ebx, 2, 12, k3)
// setup
AS2( mov esi, ebp )
ASMSubroundJ( ebx, ecx, edx, ebp, eax, 4, 9, k4)
ASMSubroundJ( eax, ebx, ecx, edx, ebp, 0, 15, k4)
ASMSubroundJ( ebp, eax, ebx, ecx, edx, 5, 5, k4)
ASMSubroundJ( edx, ebp, eax, ebx, ecx, 9, 11, k4)
ASMSubroundJ( ecx, edx, ebp, eax, ebx, 7, 6, k4)
ASMSubroundJ( ebx, ecx, edx, ebp, eax, 12, 8, k4)
ASMSubroundJ( eax, ebx, ecx, edx, ebp, 2, 13, k4)
ASMSubroundJ( ebp, eax, ebx, ecx, edx, 10, 12, k4)
ASMSubroundJ( edx, ebp, eax, ebx, ecx, 14, 5, k4)
ASMSubroundJ( ecx, edx, ebp, eax, ebx, 1, 12, k4)
ASMSubroundJ( ebx, ecx, edx, ebp, eax, 3, 13, k4)
ASMSubroundJ( eax, ebx, ecx, edx, ebp, 8, 14, k4)
ASMSubroundJ( ebp, eax, ebx, ecx, edx, 11, 11, k4)
ASMSubroundJ( edx, ebp, eax, ebx, ecx, 6, 8, k4)
ASMSubroundJ( ecx, edx, ebp, eax, ebx, 15, 5, k4)
ASMSubroundJ( ebx, ecx, edx, ebp, eax, 13, 6, k4)
// store a1 - e1 on stack
AS2( movd esi, mm1 ) // digest_
AS2( mov [esp], eax )
AS2( mov [esp + 4], ebx )
AS2( mov [esp + 8], ecx )
AS2( mov [esp + 12], edx )
AS2( mov [esp + 16], ebp )
AS2( mov eax, [esi] ) // a2
AS2( mov ebx, [esi + 4] ) // b2
AS2( mov ecx, [esi + 8] ) // c2
AS2( mov edx, [esi + 12] ) // d2
AS2( mov ebp, [esi + 16] ) // e2
// setup
AS2( mov esi, edx )
ASMSubroundJ( eax, ebx, ecx, edx, ebp, 5, 8, k5)
ASMSubroundJ( ebp, eax, ebx, ecx, edx, 14, 9, k5)
ASMSubroundJ( edx, ebp, eax, ebx, ecx, 7, 9, k5)
ASMSubroundJ( ecx, edx, ebp, eax, ebx, 0, 11, k5)
ASMSubroundJ( ebx, ecx, edx, ebp, eax, 9, 13, k5)
ASMSubroundJ( eax, ebx, ecx, edx, ebp, 2, 15, k5)
ASMSubroundJ( ebp, eax, ebx, ecx, edx, 11, 15, k5)
ASMSubroundJ( edx, ebp, eax, ebx, ecx, 4, 5, k5)
ASMSubroundJ( ecx, edx, ebp, eax, ebx, 13, 7, k5)
ASMSubroundJ( ebx, ecx, edx, ebp, eax, 6, 7, k5)
ASMSubroundJ( eax, ebx, ecx, edx, ebp, 15, 8, k5)
ASMSubroundJ( ebp, eax, ebx, ecx, edx, 8, 11, k5)
ASMSubroundJ( edx, ebp, eax, ebx, ecx, 1, 14, k5)
ASMSubroundJ( ecx, edx, ebp, eax, ebx, 10, 14, k5)
ASMSubroundJ( ebx, ecx, edx, ebp, eax, 3, 12, k5)
ASMSubroundJ( eax, ebx, ecx, edx, ebp, 12, 6, k5)
// setup
AS2( mov esi, ebx )
ASMSubroundI( ebp, eax, ebx, ecx, edx, 6, 9, k6)
ASMSubroundI( edx, ebp, eax, ebx, ecx, 11, 13, k6)
ASMSubroundI( ecx, edx, ebp, eax, ebx, 3, 15, k6)
ASMSubroundI( ebx, ecx, edx, ebp, eax, 7, 7, k6)
ASMSubroundI( eax, ebx, ecx, edx, ebp, 0, 12, k6)
ASMSubroundI( ebp, eax, ebx, ecx, edx, 13, 8, k6)
ASMSubroundI( edx, ebp, eax, ebx, ecx, 5, 9, k6)
ASMSubroundI( ecx, edx, ebp, eax, ebx, 10, 11, k6)
ASMSubroundI( ebx, ecx, edx, ebp, eax, 14, 7, k6)
ASMSubroundI( eax, ebx, ecx, edx, ebp, 15, 7, k6)
ASMSubroundI( ebp, eax, ebx, ecx, edx, 8, 12, k6)
ASMSubroundI( edx, ebp, eax, ebx, ecx, 12, 7, k6)
ASMSubroundI( ecx, edx, ebp, eax, ebx, 4, 6, k6)
ASMSubroundI( ebx, ecx, edx, ebp, eax, 9, 15, k6)
ASMSubroundI( eax, ebx, ecx, edx, ebp, 1, 13, k6)
ASMSubroundI( ebp, eax, ebx, ecx, edx, 2, 11, k6)
ASMSubroundH( edx, ebp, eax, ebx, ecx, 15, 9, k7)
ASMSubroundH( ecx, edx, ebp, eax, ebx, 5, 7, k7)
ASMSubroundH( ebx, ecx, edx, ebp, eax, 1, 15, k7)
ASMSubroundH( eax, ebx, ecx, edx, ebp, 3, 11, k7)
ASMSubroundH( ebp, eax, ebx, ecx, edx, 7, 8, k7)
ASMSubroundH( edx, ebp, eax, ebx, ecx, 14, 6, k7)
ASMSubroundH( ecx, edx, ebp, eax, ebx, 6, 6, k7)
ASMSubroundH( ebx, ecx, edx, ebp, eax, 9, 14, k7)
ASMSubroundH( eax, ebx, ecx, edx, ebp, 11, 12, k7)
ASMSubroundH( ebp, eax, ebx, ecx, edx, 8, 13, k7)
ASMSubroundH( edx, ebp, eax, ebx, ecx, 12, 5, k7)
ASMSubroundH( ecx, edx, ebp, eax, ebx, 2, 14, k7)
ASMSubroundH( ebx, ecx, edx, ebp, eax, 10, 13, k7)
ASMSubroundH( eax, ebx, ecx, edx, ebp, 0, 13, k7)
ASMSubroundH( ebp, eax, ebx, ecx, edx, 4, 7, k7)
ASMSubroundH( edx, ebp, eax, ebx, ecx, 13, 5, k7)
ASMSubroundG( ecx, edx, ebp, eax, ebx, 8, 15, k8)
ASMSubroundG( ebx, ecx, edx, ebp, eax, 6, 5, k8)
ASMSubroundG( eax, ebx, ecx, edx, ebp, 4, 8, k8)
ASMSubroundG( ebp, eax, ebx, ecx, edx, 1, 11, k8)
ASMSubroundG( edx, ebp, eax, ebx, ecx, 3, 14, k8)
ASMSubroundG( ecx, edx, ebp, eax, ebx, 11, 14, k8)
ASMSubroundG( ebx, ecx, edx, ebp, eax, 15, 6, k8)
ASMSubroundG( eax, ebx, ecx, edx, ebp, 0, 14, k8)
ASMSubroundG( ebp, eax, ebx, ecx, edx, 5, 6, k8)
ASMSubroundG( edx, ebp, eax, ebx, ecx, 12, 9, k8)
ASMSubroundG( ecx, edx, ebp, eax, ebx, 2, 12, k8)
ASMSubroundG( ebx, ecx, edx, ebp, eax, 13, 9, k8)
ASMSubroundG( eax, ebx, ecx, edx, ebp, 9, 12, k8)
ASMSubroundG( ebp, eax, ebx, ecx, edx, 7, 5, k8)
ASMSubroundG( edx, ebp, eax, ebx, ecx, 10, 15, k8)
ASMSubroundG( ecx, edx, ebp, eax, ebx, 14, 8, k8)
ASMSubroundF( ebx, ecx, edx, ebp, eax, 12, 8)
ASMSubroundF( eax, ebx, ecx, edx, ebp, 15, 5)
ASMSubroundF( ebp, eax, ebx, ecx, edx, 10, 12)
ASMSubroundF( edx, ebp, eax, ebx, ecx, 4, 9)
ASMSubroundF( ecx, edx, ebp, eax, ebx, 1, 12)
ASMSubroundF( ebx, ecx, edx, ebp, eax, 5, 5)
ASMSubroundF( eax, ebx, ecx, edx, ebp, 8, 14)
ASMSubroundF( ebp, eax, ebx, ecx, edx, 7, 6)
ASMSubroundF( edx, ebp, eax, ebx, ecx, 6, 8)
ASMSubroundF( ecx, edx, ebp, eax, ebx, 2, 13)
ASMSubroundF( ebx, ecx, edx, ebp, eax, 13, 6)
ASMSubroundF( eax, ebx, ecx, edx, ebp, 14, 5)
ASMSubroundF( ebp, eax, ebx, ecx, edx, 0, 15)
ASMSubroundF( edx, ebp, eax, ebx, ecx, 3, 13)
ASMSubroundF( ecx, edx, ebp, eax, ebx, 9, 11)
ASMSubroundF( ebx, ecx, edx, ebp, eax, 11, 11)
// advance data and store for next round
AS2( add edi, 64 )
AS2( movd esi, mm1 ) // digest_
AS2( movd mm0, edi ) // store
// now edi as tmp
// c1 = digest_[1] + c1 + d2;
AS2( add [esp + 8], edx ) // + d2
AS2( mov edi, [esi + 4] ) // digest_[1]
AS2( add [esp + 8], edi )
// digest_[1] = digest_[2] + d1 + e2;
AS2( mov [esi + 4], ebp ) // e2
AS2( mov edi, [esp + 12] ) // d1
AS2( add edi, [esi + 8] ) // digest_[2]
AS2( add [esi + 4], edi )
// digest_[2] = digest_[3] + e1 + a2;
AS2( mov [esi + 8], eax ) // a2
AS2( mov edi, [esp + 16] ) // e1
AS2( add edi, [esi + 12] ) // digest_[3]
AS2( add [esi + 8], edi )
// digest_[3] = digest_[4] + a1 + b2;
AS2( mov [esi + 12], ebx ) // b2
AS2( mov edi, [esp] ) // a1
AS2( add edi, [esi + 16] ) // digest_[4]
AS2( add [esi + 12], edi )
// digest_[4] = digest_[0] + b1 + c2;
AS2( mov [esi + 16], ecx ) // c2
AS2( mov edi, [esp + 4] ) // b1
AS2( add edi, [esi] ) // digest_[0]
AS2( add [esi + 16], edi )
// digest_[0] = c1;
AS2( mov edi, [esp + 8] ) // c1
AS2( mov [esi], edi )
// setup for loop back
AS2( movd edx, mm2 ) // times
AS2( movd edi, mm0 ) // data, already advanced
AS1( dec edx )
AS1( jnz loopStart )
EPILOG()
}
#endif // DO_RIPEMD_ASM
} // namespace TaoCrypt

View File

@ -27,6 +27,11 @@
#include "sha.hpp"
#if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
#define DO_SHA_ASM
#endif
namespace TaoCrypt {
#define blk0(i) (W[i] = buffer_[i])
@ -60,7 +65,8 @@ void SHA::Init()
digest_[4] = 0xC3D2E1F0L;
buffLen_ = 0;
length_ = 0;
loLen_ = 0;
hiLen_ = 0;
}
@ -68,7 +74,8 @@ SHA::SHA(const SHA& that) : HASHwithTransform(DIGEST_SIZE / sizeof(word32),
BLOCK_SIZE)
{
buffLen_ = that.buffLen_;
length_ = that.length_;
loLen_ = that.loLen_;
hiLen_ = that.hiLen_;
memcpy(digest_, that.digest_, DIGEST_SIZE);
memcpy(buffer_, that.buffer_, BLOCK_SIZE);
@ -85,7 +92,8 @@ SHA& SHA::operator= (const SHA& that)
void SHA::Swap(SHA& other)
{
mySTL::swap(length_, other.length_);
mySTL::swap(loLen_, other.loLen_);
mySTL::swap(hiLen_, other.hiLen_);
mySTL::swap(buffLen_, other.buffLen_);
memcpy(digest_, other.digest_, DIGEST_SIZE);
@ -93,6 +101,61 @@ void SHA::Swap(SHA& other)
}
// Update digest with data of size len, do in blocks
void SHA::Update(const byte* data, word32 len)
{
byte* local = (byte*)buffer_;
// remove buffered data if possible
if (buffLen_) {
word32 add = min(len, BLOCK_SIZE - buffLen_);
memcpy(&local[buffLen_], data, add);
buffLen_ += add;
data += add;
len -= add;
if (buffLen_ == BLOCK_SIZE) {
ByteReverseIf(local, local, BLOCK_SIZE, BigEndianOrder);
Transform();
AddLength(BLOCK_SIZE);
buffLen_ = 0;
}
}
// do block size transforms or all at once for asm
if (buffLen_ == 0) {
#ifndef DO_SHA_ASM
while (len >= BLOCK_SIZE) {
memcpy(&local[0], data, BLOCK_SIZE);
data += BLOCK_SIZE;
len -= BLOCK_SIZE;
ByteReverseIf(local, local, BLOCK_SIZE, BigEndianOrder);
Transform();
AddLength(BLOCK_SIZE);
}
#else
word32 times = len / BLOCK_SIZE;
if (times) {
AsmTransform(data, times);
const word32 add = BLOCK_SIZE * times;
AddLength(add);
len -= add;
data += add;
}
#endif
}
// cache any data left
if (len) {
memcpy(&local[buffLen_], data, len);
buffLen_ += len;
}
}
void SHA::Transform()
{
word32 W[BLOCK_SIZE / sizeof(word32)];
@ -109,17 +172,21 @@ void SHA::Transform()
R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
@ -136,10 +203,414 @@ void SHA::Transform()
// Wipe variables
a = b = c = d = e = 0;
memset(W, 0, sizeof(W));
buffLen_ = 0;
length_ += 512;
}
#ifdef DO_SHA_ASM
// f1(x,y,z) (z^(x &(y^z)))
// place in esi
#define ASMf1(x,y,z) \
AS2( mov esi, y ) \
AS2( xor esi, z ) \
AS2( and esi, x ) \
AS2( xor esi, z )
// R0(v,w,x,y,z,i) =
// z+= f1(w,x,y) + W[i] + 0x5A827999 + rotlFixed(v,5);
// w = rotlFixed(w,30);
// use esi for f
// use edi as tmp
#define ASMR0(v,w,x,y,z,i) \
AS2( mov esi, x ) \
AS2( mov edi, [esp + i * 4] ) \
AS2( xor esi, y ) \
AS2( and esi, w ) \
AS2( lea z, [edi + z + 0x5A827999] ) \
AS2( mov edi, v ) \
AS2( xor esi, y ) \
AS2( rol edi, 5 ) \
AS2( add z, esi ) \
AS2( rol w, 30 ) \
AS2( add z, edi )
/* Some macro stuff, but older gas ( < 2,16 ) can't process &, so do by hand
% won't work on gas at all
#define xstr(s) str(s)
#define str(s) #s
#define WOFF1(a) ( a & 15)
#define WOFF2(a) ((a + 2) & 15)
#define WOFF3(a) ((a + 8) & 15)
#define WOFF4(a) ((a + 13) & 15)
#ifdef __GNUC__
#define WGET1(i) asm("mov esp, [edi - "xstr(WOFF1(i))" * 4] ");
#define WGET2(i) asm("xor esp, [edi - "xstr(WOFF2(i))" * 4] ");
#define WGET3(i) asm("xor esp, [edi - "xstr(WOFF3(i))" * 4] ");
#define WGET4(i) asm("xor esp, [edi - "xstr(WOFF4(i))" * 4] ");
#define WPUT1(i) asm("mov [edi - "xstr(WOFF1(i))" * 4], esp ");
#else
#define WGET1(i) AS2( mov esp, [edi - WOFF1(i) * 4] )
#define WGET2(i) AS2( xor esp, [edi - WOFF2(i) * 4] )
#define WGET3(i) AS2( xor esp, [edi - WOFF3(i) * 4] )
#define WGET4(i) AS2( xor esp, [edi - WOFF4(i) * 4] )
#define WPUT1(i) AS2( mov [edi - WOFF1(i) * 4], esp )
#endif
*/
// ASMR1 = ASMR0 but use esp for W calcs
#define ASMR1(v,w,x,y,z,i,W1,W2,W3,W4) \
AS2( mov edi, [esp + W1 * 4] ) \
AS2( mov esi, x ) \
AS2( xor edi, [esp + W2 * 4] ) \
AS2( xor esi, y ) \
AS2( xor edi, [esp + W3 * 4] ) \
AS2( and esi, w ) \
AS2( xor edi, [esp + W4 * 4] ) \
AS2( rol edi, 1 ) \
AS2( xor esi, y ) \
AS2( mov [esp + W1 * 4], edi ) \
AS2( lea z, [edi + z + 0x5A827999] ) \
AS2( mov edi, v ) \
AS2( rol edi, 5 ) \
AS2( add z, esi ) \
AS2( rol w, 30 ) \
AS2( add z, edi )
// ASMR2 = ASMR1 but f is xor, xor instead
#define ASMR2(v,w,x,y,z,i,W1,W2,W3,W4) \
AS2( mov edi, [esp + W1 * 4] ) \
AS2( mov esi, x ) \
AS2( xor edi, [esp + W2 * 4] ) \
AS2( xor esi, y ) \
AS2( xor edi, [esp + W3 * 4] ) \
AS2( xor esi, w ) \
AS2( xor edi, [esp + W4 * 4] ) \
AS2( rol edi, 1 ) \
AS2( add z, esi ) \
AS2( mov [esp + W1 * 4], edi ) \
AS2( lea z, [edi + z + 0x6ED9EBA1] ) \
AS2( mov edi, v ) \
AS2( rol edi, 5 ) \
AS2( rol w, 30 ) \
AS2( add z, edi )
// ASMR3 = ASMR2 but f is (x&y)|(z&(x|y))
// which is (w&x)|(y&(w|x))
#define ASMR3(v,w,x,y,z,i,W1,W2,W3,W4) \
AS2( mov edi, [esp + W1 * 4] ) \
AS2( mov esi, x ) \
AS2( xor edi, [esp + W2 * 4] ) \
AS2( or esi, w ) \
AS2( xor edi, [esp + W3 * 4] ) \
AS2( and esi, y ) \
AS2( xor edi, [esp + W4 * 4] ) \
AS2( movd mm0, esi ) \
AS2( rol edi, 1 ) \
AS2( mov esi, x ) \
AS2( mov [esp + W1 * 4], edi ) \
AS2( and esi, w ) \
AS2( lea z, [edi + z + 0x8F1BBCDC] ) \
AS2( movd edi, mm0 ) \
AS2( or esi, edi ) \
AS2( mov edi, v ) \
AS2( rol edi, 5 ) \
AS2( add z, esi ) \
AS2( rol w, 30 ) \
AS2( add z, edi )
// ASMR4 = ASMR2 but different constant
#define ASMR4(v,w,x,y,z,i,W1,W2,W3,W4) \
AS2( mov edi, [esp + W1 * 4] ) \
AS2( mov esi, x ) \
AS2( xor edi, [esp + W2 * 4] ) \
AS2( xor esi, y ) \
AS2( xor edi, [esp + W3 * 4] ) \
AS2( xor esi, w ) \
AS2( xor edi, [esp + W4 * 4] ) \
AS2( rol edi, 1 ) \
AS2( add z, esi ) \
AS2( mov [esp + W1 * 4], edi ) \
AS2( lea z, [edi + z + 0xCA62C1D6] ) \
AS2( mov edi, v ) \
AS2( rol edi, 5 ) \
AS2( rol w, 30 ) \
AS2( add z, edi )
#ifdef _MSC_VER
__declspec(naked)
#endif
void SHA::AsmTransform(const byte* data, word32 times)
{
#ifdef __GNUC__
#define AS1(x) asm(#x);
#define AS2(x, y) asm(#x ", " #y);
#define PROLOG() \
asm(".intel_syntax noprefix"); \
AS2( movd mm3, edi ) \
AS2( movd mm4, ebx ) \
AS2( movd mm5, esi ) \
AS2( movd mm6, ebp ) \
AS2( mov ecx, DWORD PTR [ebp + 8] ) \
AS2( mov edi, DWORD PTR [ebp + 12] ) \
AS2( mov eax, DWORD PTR [ebp + 16] )
#define EPILOG() \
AS2( movd ebp, mm6 ) \
AS2( movd esi, mm5 ) \
AS2( movd ebx, mm4 ) \
AS2( mov esp, ebp ) \
AS2( movd edi, mm3 ) \
AS1( emms ) \
asm(".att_syntax");
#else
#define AS1(x) __asm x
#define AS2(x, y) __asm x, y
#define PROLOG() \
AS1( push ebp ) \
AS2( mov ebp, esp ) \
AS2( movd mm3, edi ) \
AS2( movd mm4, ebx ) \
AS2( movd mm5, esi ) \
AS2( movd mm6, ebp ) \
AS2( mov edi, data ) \
AS2( mov eax, times )
#define EPILOG() \
AS2( movd ebp, mm6 ) \
AS2( movd esi, mm5 ) \
AS2( movd ebx, mm4 ) \
AS2( movd edi, mm3 ) \
AS2( mov esp, ebp ) \
AS1( pop ebp ) \
AS1( emms ) \
AS1( ret 8 )
#endif
PROLOG()
AS2( mov esi, ecx )
#ifdef OLD_GCC_OFFSET
AS2( add esi, 20 ) // digest_[0]
#else
AS2( add esi, 16 ) // digest_[0]
#endif
AS2( movd mm2, eax ) // store times_
AS2( movd mm1, esi ) // store digest_
AS2( sub esp, 68 ) // make room on stack
AS1( loopStart: )
// byte reverse 16 words of input, 4 at a time, put on stack for W[]
// part 1
AS2( mov eax, [edi] )
AS2( mov ebx, [edi + 4] )
AS2( mov ecx, [edi + 8] )
AS2( mov edx, [edi + 12] )
AS1( bswap eax )
AS1( bswap ebx )
AS1( bswap ecx )
AS1( bswap edx )
AS2( mov [esp], eax )
AS2( mov [esp + 4], ebx )
AS2( mov [esp + 8], ecx )
AS2( mov [esp + 12], edx )
// part 2
AS2( mov eax, [edi + 16] )
AS2( mov ebx, [edi + 20] )
AS2( mov ecx, [edi + 24] )
AS2( mov edx, [edi + 28] )
AS1( bswap eax )
AS1( bswap ebx )
AS1( bswap ecx )
AS1( bswap edx )
AS2( mov [esp + 16], eax )
AS2( mov [esp + 20], ebx )
AS2( mov [esp + 24], ecx )
AS2( mov [esp + 28], edx )
// part 3
AS2( mov eax, [edi + 32] )
AS2( mov ebx, [edi + 36] )
AS2( mov ecx, [edi + 40] )
AS2( mov edx, [edi + 44] )
AS1( bswap eax )
AS1( bswap ebx )
AS1( bswap ecx )
AS1( bswap edx )
AS2( mov [esp + 32], eax )
AS2( mov [esp + 36], ebx )
AS2( mov [esp + 40], ecx )
AS2( mov [esp + 44], edx )
// part 4
AS2( mov eax, [edi + 48] )
AS2( mov ebx, [edi + 52] )
AS2( mov ecx, [edi + 56] )
AS2( mov edx, [edi + 60] )
AS1( bswap eax )
AS1( bswap ebx )
AS1( bswap ecx )
AS1( bswap edx )
AS2( mov [esp + 48], eax )
AS2( mov [esp + 52], ebx )
AS2( mov [esp + 56], ecx )
AS2( mov [esp + 60], edx )
AS2( mov [esp + 64], edi ) // store edi for end
// read from digest_
AS2( mov eax, [esi] ) // a1
AS2( mov ebx, [esi + 4] ) // b1
AS2( mov ecx, [esi + 8] ) // c1
AS2( mov edx, [esi + 12] ) // d1
AS2( mov ebp, [esi + 16] ) // e1
ASMR0(eax, ebx, ecx, edx, ebp, 0)
ASMR0(ebp, eax, ebx, ecx, edx, 1)
ASMR0(edx, ebp, eax, ebx, ecx, 2)
ASMR0(ecx, edx, ebp, eax, ebx, 3)
ASMR0(ebx, ecx, edx, ebp, eax, 4)
ASMR0(eax, ebx, ecx, edx, ebp, 5)
ASMR0(ebp, eax, ebx, ecx, edx, 6)
ASMR0(edx, ebp, eax, ebx, ecx, 7)
ASMR0(ecx, edx, ebp, eax, ebx, 8)
ASMR0(ebx, ecx, edx, ebp, eax, 9)
ASMR0(eax, ebx, ecx, edx, ebp, 10)
ASMR0(ebp, eax, ebx, ecx, edx, 11)
ASMR0(edx, ebp, eax, ebx, ecx, 12)
ASMR0(ecx, edx, ebp, eax, ebx, 13)
ASMR0(ebx, ecx, edx, ebp, eax, 14)
ASMR0(eax, ebx, ecx, edx, ebp, 15)
ASMR1(ebp, eax, ebx, ecx, edx, 16, 0, 2, 8, 13)
ASMR1(edx, ebp, eax, ebx, ecx, 17, 1, 3, 9, 14)
ASMR1(ecx, edx, ebp, eax, ebx, 18, 2, 4, 10, 15)
ASMR1(ebx, ecx, edx, ebp, eax, 19, 3, 5, 11, 0)
ASMR2(eax, ebx, ecx, edx, ebp, 20, 4, 6, 12, 1)
ASMR2(ebp, eax, ebx, ecx, edx, 21, 5, 7, 13, 2)
ASMR2(edx, ebp, eax, ebx, ecx, 22, 6, 8, 14, 3)
ASMR2(ecx, edx, ebp, eax, ebx, 23, 7, 9, 15, 4)
ASMR2(ebx, ecx, edx, ebp, eax, 24, 8, 10, 0, 5)
ASMR2(eax, ebx, ecx, edx, ebp, 25, 9, 11, 1, 6)
ASMR2(ebp, eax, ebx, ecx, edx, 26, 10, 12, 2, 7)
ASMR2(edx, ebp, eax, ebx, ecx, 27, 11, 13, 3, 8)
ASMR2(ecx, edx, ebp, eax, ebx, 28, 12, 14, 4, 9)
ASMR2(ebx, ecx, edx, ebp, eax, 29, 13, 15, 5, 10)
ASMR2(eax, ebx, ecx, edx, ebp, 30, 14, 0, 6, 11)
ASMR2(ebp, eax, ebx, ecx, edx, 31, 15, 1, 7, 12)
ASMR2(edx, ebp, eax, ebx, ecx, 32, 0, 2, 8, 13)
ASMR2(ecx, edx, ebp, eax, ebx, 33, 1, 3, 9, 14)
ASMR2(ebx, ecx, edx, ebp, eax, 34, 2, 4, 10, 15)
ASMR2(eax, ebx, ecx, edx, ebp, 35, 3, 5, 11, 0)
ASMR2(ebp, eax, ebx, ecx, edx, 36, 4, 6, 12, 1)
ASMR2(edx, ebp, eax, ebx, ecx, 37, 5, 7, 13, 2)
ASMR2(ecx, edx, ebp, eax, ebx, 38, 6, 8, 14, 3)
ASMR2(ebx, ecx, edx, ebp, eax, 39, 7, 9, 15, 4)
ASMR3(eax, ebx, ecx, edx, ebp, 40, 8, 10, 0, 5)
ASMR3(ebp, eax, ebx, ecx, edx, 41, 9, 11, 1, 6)
ASMR3(edx, ebp, eax, ebx, ecx, 42, 10, 12, 2, 7)
ASMR3(ecx, edx, ebp, eax, ebx, 43, 11, 13, 3, 8)
ASMR3(ebx, ecx, edx, ebp, eax, 44, 12, 14, 4, 9)
ASMR3(eax, ebx, ecx, edx, ebp, 45, 13, 15, 5, 10)
ASMR3(ebp, eax, ebx, ecx, edx, 46, 14, 0, 6, 11)
ASMR3(edx, ebp, eax, ebx, ecx, 47, 15, 1, 7, 12)
ASMR3(ecx, edx, ebp, eax, ebx, 48, 0, 2, 8, 13)
ASMR3(ebx, ecx, edx, ebp, eax, 49, 1, 3, 9, 14)
ASMR3(eax, ebx, ecx, edx, ebp, 50, 2, 4, 10, 15)
ASMR3(ebp, eax, ebx, ecx, edx, 51, 3, 5, 11, 0)
ASMR3(edx, ebp, eax, ebx, ecx, 52, 4, 6, 12, 1)
ASMR3(ecx, edx, ebp, eax, ebx, 53, 5, 7, 13, 2)
ASMR3(ebx, ecx, edx, ebp, eax, 54, 6, 8, 14, 3)
ASMR3(eax, ebx, ecx, edx, ebp, 55, 7, 9, 15, 4)
ASMR3(ebp, eax, ebx, ecx, edx, 56, 8, 10, 0, 5)
ASMR3(edx, ebp, eax, ebx, ecx, 57, 9, 11, 1, 6)
ASMR3(ecx, edx, ebp, eax, ebx, 58, 10, 12, 2, 7)
ASMR3(ebx, ecx, edx, ebp, eax, 59, 11, 13, 3, 8)
ASMR4(eax, ebx, ecx, edx, ebp, 60, 12, 14, 4, 9)
ASMR4(ebp, eax, ebx, ecx, edx, 61, 13, 15, 5, 10)
ASMR4(edx, ebp, eax, ebx, ecx, 62, 14, 0, 6, 11)
ASMR4(ecx, edx, ebp, eax, ebx, 63, 15, 1, 7, 12)
ASMR4(ebx, ecx, edx, ebp, eax, 64, 0, 2, 8, 13)
ASMR4(eax, ebx, ecx, edx, ebp, 65, 1, 3, 9, 14)
ASMR4(ebp, eax, ebx, ecx, edx, 66, 2, 4, 10, 15)
ASMR4(edx, ebp, eax, ebx, ecx, 67, 3, 5, 11, 0)
ASMR4(ecx, edx, ebp, eax, ebx, 68, 4, 6, 12, 1)
ASMR4(ebx, ecx, edx, ebp, eax, 69, 5, 7, 13, 2)
ASMR4(eax, ebx, ecx, edx, ebp, 70, 6, 8, 14, 3)
ASMR4(ebp, eax, ebx, ecx, edx, 71, 7, 9, 15, 4)
ASMR4(edx, ebp, eax, ebx, ecx, 72, 8, 10, 0, 5)
ASMR4(ecx, edx, ebp, eax, ebx, 73, 9, 11, 1, 6)
ASMR4(ebx, ecx, edx, ebp, eax, 74, 10, 12, 2, 7)
ASMR4(eax, ebx, ecx, edx, ebp, 75, 11, 13, 3, 8)
ASMR4(ebp, eax, ebx, ecx, edx, 76, 12, 14, 4, 9)
ASMR4(edx, ebp, eax, ebx, ecx, 77, 13, 15, 5, 10)
ASMR4(ecx, edx, ebp, eax, ebx, 78, 14, 0, 6, 11)
ASMR4(ebx, ecx, edx, ebp, eax, 79, 15, 1, 7, 12)
AS2( movd esi, mm1 ) // digest_
AS2( add [esi], eax ) // write out
AS2( add [esi + 4], ebx )
AS2( add [esi + 8], ecx )
AS2( add [esi + 12], edx )
AS2( add [esi + 16], ebp )
// setup next round
AS2( movd ebp, mm2 ) // times
AS2( mov edi, DWORD PTR [esp + 64] ) // data
AS2( add edi, 64 ) // next round of data
AS2( mov [esp + 64], edi ) // restore
AS1( dec ebp )
AS2( movd mm2, ebp )
AS1( jnz loopStart )
EPILOG()
}
#endif // DO_SHA_ASM
} // namespace

View File

@ -24,8 +24,14 @@
*/
#include "runtime.hpp"
#include "integer.hpp"
#include "rsa.hpp"
#include "sha.hpp"
#include "md5.hpp"
#include "hmac.hpp"
#include "ripemd.hpp"
#include "pwdbased.hpp"
#include "algebra.hpp"
#include "vector.hpp"
#include "hash.hpp"
@ -53,6 +59,12 @@ template AllocatorWithCleanup<word32>::pointer StdReallocate<word32, AllocatorWi
#endif
template void tcArrayDelete<char>(char*);
template class PBKDF2_HMAC<SHA>;
template class HMAC<MD5>;
template class HMAC<SHA>;
template class HMAC<RIPEMD160>;
}
namespace mySTL {

View File

@ -0,0 +1,352 @@
/* tftables.cpp
*
* Copyright (C) 2003 Sawtooth Consulting Ltd.
*
* This file is part of yaSSL.
*
* yaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* yaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/* based on Wei Dai's tftables.cpp from CryptoPP */
#include "runtime.hpp"
#include "twofish.hpp"
namespace TaoCrypt {
const byte Twofish::q_[2][256] = {
{
0xA9, 0x67, 0xB3, 0xE8, 0x04, 0xFD, 0xA3, 0x76, 0x9A, 0x92, 0x80, 0x78,
0xE4, 0xDD, 0xD1, 0x38, 0x0D, 0xC6, 0x35, 0x98, 0x18, 0xF7, 0xEC, 0x6C,
0x43, 0x75, 0x37, 0x26, 0xFA, 0x13, 0x94, 0x48, 0xF2, 0xD0, 0x8B, 0x30,
0x84, 0x54, 0xDF, 0x23, 0x19, 0x5B, 0x3D, 0x59, 0xF3, 0xAE, 0xA2, 0x82,
0x63, 0x01, 0x83, 0x2E, 0xD9, 0x51, 0x9B, 0x7C, 0xA6, 0xEB, 0xA5, 0xBE,
0x16, 0x0C, 0xE3, 0x61, 0xC0, 0x8C, 0x3A, 0xF5, 0x73, 0x2C, 0x25, 0x0B,
0xBB, 0x4E, 0x89, 0x6B, 0x53, 0x6A, 0xB4, 0xF1, 0xE1, 0xE6, 0xBD, 0x45,
0xE2, 0xF4, 0xB6, 0x66, 0xCC, 0x95, 0x03, 0x56, 0xD4, 0x1C, 0x1E, 0xD7,
0xFB, 0xC3, 0x8E, 0xB5, 0xE9, 0xCF, 0xBF, 0xBA, 0xEA, 0x77, 0x39, 0xAF,
0x33, 0xC9, 0x62, 0x71, 0x81, 0x79, 0x09, 0xAD, 0x24, 0xCD, 0xF9, 0xD8,
0xE5, 0xC5, 0xB9, 0x4D, 0x44, 0x08, 0x86, 0xE7, 0xA1, 0x1D, 0xAA, 0xED,
0x06, 0x70, 0xB2, 0xD2, 0x41, 0x7B, 0xA0, 0x11, 0x31, 0xC2, 0x27, 0x90,
0x20, 0xF6, 0x60, 0xFF, 0x96, 0x5C, 0xB1, 0xAB, 0x9E, 0x9C, 0x52, 0x1B,
0x5F, 0x93, 0x0A, 0xEF, 0x91, 0x85, 0x49, 0xEE, 0x2D, 0x4F, 0x8F, 0x3B,
0x47, 0x87, 0x6D, 0x46, 0xD6, 0x3E, 0x69, 0x64, 0x2A, 0xCE, 0xCB, 0x2F,
0xFC, 0x97, 0x05, 0x7A, 0xAC, 0x7F, 0xD5, 0x1A, 0x4B, 0x0E, 0xA7, 0x5A,
0x28, 0x14, 0x3F, 0x29, 0x88, 0x3C, 0x4C, 0x02, 0xB8, 0xDA, 0xB0, 0x17,
0x55, 0x1F, 0x8A, 0x7D, 0x57, 0xC7, 0x8D, 0x74, 0xB7, 0xC4, 0x9F, 0x72,
0x7E, 0x15, 0x22, 0x12, 0x58, 0x07, 0x99, 0x34, 0x6E, 0x50, 0xDE, 0x68,
0x65, 0xBC, 0xDB, 0xF8, 0xC8, 0xA8, 0x2B, 0x40, 0xDC, 0xFE, 0x32, 0xA4,
0xCA, 0x10, 0x21, 0xF0, 0xD3, 0x5D, 0x0F, 0x00, 0x6F, 0x9D, 0x36, 0x42,
0x4A, 0x5E, 0xC1, 0xE0
},
{
0x75, 0xF3, 0xC6, 0xF4, 0xDB, 0x7B, 0xFB, 0xC8, 0x4A, 0xD3, 0xE6, 0x6B,
0x45, 0x7D, 0xE8, 0x4B, 0xD6, 0x32, 0xD8, 0xFD, 0x37, 0x71, 0xF1, 0xE1,
0x30, 0x0F, 0xF8, 0x1B, 0x87, 0xFA, 0x06, 0x3F, 0x5E, 0xBA, 0xAE, 0x5B,
0x8A, 0x00, 0xBC, 0x9D, 0x6D, 0xC1, 0xB1, 0x0E, 0x80, 0x5D, 0xD2, 0xD5,
0xA0, 0x84, 0x07, 0x14, 0xB5, 0x90, 0x2C, 0xA3, 0xB2, 0x73, 0x4C, 0x54,
0x92, 0x74, 0x36, 0x51, 0x38, 0xB0, 0xBD, 0x5A, 0xFC, 0x60, 0x62, 0x96,
0x6C, 0x42, 0xF7, 0x10, 0x7C, 0x28, 0x27, 0x8C, 0x13, 0x95, 0x9C, 0xC7,
0x24, 0x46, 0x3B, 0x70, 0xCA, 0xE3, 0x85, 0xCB, 0x11, 0xD0, 0x93, 0xB8,
0xA6, 0x83, 0x20, 0xFF, 0x9F, 0x77, 0xC3, 0xCC, 0x03, 0x6F, 0x08, 0xBF,
0x40, 0xE7, 0x2B, 0xE2, 0x79, 0x0C, 0xAA, 0x82, 0x41, 0x3A, 0xEA, 0xB9,
0xE4, 0x9A, 0xA4, 0x97, 0x7E, 0xDA, 0x7A, 0x17, 0x66, 0x94, 0xA1, 0x1D,
0x3D, 0xF0, 0xDE, 0xB3, 0x0B, 0x72, 0xA7, 0x1C, 0xEF, 0xD1, 0x53, 0x3E,
0x8F, 0x33, 0x26, 0x5F, 0xEC, 0x76, 0x2A, 0x49, 0x81, 0x88, 0xEE, 0x21,
0xC4, 0x1A, 0xEB, 0xD9, 0xC5, 0x39, 0x99, 0xCD, 0xAD, 0x31, 0x8B, 0x01,
0x18, 0x23, 0xDD, 0x1F, 0x4E, 0x2D, 0xF9, 0x48, 0x4F, 0xF2, 0x65, 0x8E,
0x78, 0x5C, 0x58, 0x19, 0x8D, 0xE5, 0x98, 0x57, 0x67, 0x7F, 0x05, 0x64,
0xAF, 0x63, 0xB6, 0xFE, 0xF5, 0xB7, 0x3C, 0xA5, 0xCE, 0xE9, 0x68, 0x44,
0xE0, 0x4D, 0x43, 0x69, 0x29, 0x2E, 0xAC, 0x15, 0x59, 0xA8, 0x0A, 0x9E,
0x6E, 0x47, 0xDF, 0x34, 0x35, 0x6A, 0xCF, 0xDC, 0x22, 0xC9, 0xC0, 0x9B,
0x89, 0xD4, 0xED, 0xAB, 0x12, 0xA2, 0x0D, 0x52, 0xBB, 0x02, 0x2F, 0xA9,
0xD7, 0x61, 0x1E, 0xB4, 0x50, 0x04, 0xF6, 0xC2, 0x16, 0x25, 0x86, 0x56,
0x55, 0x09, 0xBE, 0x91
}
};
const word32 Twofish::mds_[4][256] = {
{
0xbcbc3275, 0xecec21f3, 0x202043c6, 0xb3b3c9f4,
0xdada03db, 0x02028b7b, 0xe2e22bfb, 0x9e9efac8,
0xc9c9ec4a, 0xd4d409d3, 0x18186be6, 0x1e1e9f6b,
0x98980e45, 0xb2b2387d, 0xa6a6d2e8, 0x2626b74b,
0x3c3c57d6, 0x93938a32, 0x8282eed8, 0x525298fd,
0x7b7bd437, 0xbbbb3771, 0x5b5b97f1, 0x474783e1,
0x24243c30, 0x5151e20f, 0xbabac6f8, 0x4a4af31b,
0xbfbf4887, 0x0d0d70fa, 0xb0b0b306, 0x7575de3f,
0xd2d2fd5e, 0x7d7d20ba, 0x666631ae, 0x3a3aa35b,
0x59591c8a, 0x00000000, 0xcdcd93bc, 0x1a1ae09d,
0xaeae2c6d, 0x7f7fabc1, 0x2b2bc7b1, 0xbebeb90e,
0xe0e0a080, 0x8a8a105d, 0x3b3b52d2, 0x6464bad5,
0xd8d888a0, 0xe7e7a584, 0x5f5fe807, 0x1b1b1114,
0x2c2cc2b5, 0xfcfcb490, 0x3131272c, 0x808065a3,
0x73732ab2, 0x0c0c8173, 0x79795f4c, 0x6b6b4154,
0x4b4b0292, 0x53536974, 0x94948f36, 0x83831f51,
0x2a2a3638, 0xc4c49cb0, 0x2222c8bd, 0xd5d5f85a,
0xbdbdc3fc, 0x48487860, 0xffffce62, 0x4c4c0796,
0x4141776c, 0xc7c7e642, 0xebeb24f7, 0x1c1c1410,
0x5d5d637c, 0x36362228, 0x6767c027, 0xe9e9af8c,
0x4444f913, 0x1414ea95, 0xf5f5bb9c, 0xcfcf18c7,
0x3f3f2d24, 0xc0c0e346, 0x7272db3b, 0x54546c70,
0x29294cca, 0xf0f035e3, 0x0808fe85, 0xc6c617cb,
0xf3f34f11, 0x8c8ce4d0, 0xa4a45993, 0xcaca96b8,
0x68683ba6, 0xb8b84d83, 0x38382820, 0xe5e52eff,
0xadad569f, 0x0b0b8477, 0xc8c81dc3, 0x9999ffcc,
0x5858ed03, 0x19199a6f, 0x0e0e0a08, 0x95957ebf,
0x70705040, 0xf7f730e7, 0x6e6ecf2b, 0x1f1f6ee2,
0xb5b53d79, 0x09090f0c, 0x616134aa, 0x57571682,
0x9f9f0b41, 0x9d9d803a, 0x111164ea, 0x2525cdb9,
0xafafdde4, 0x4545089a, 0xdfdf8da4, 0xa3a35c97,
0xeaead57e, 0x353558da, 0xededd07a, 0x4343fc17,
0xf8f8cb66, 0xfbfbb194, 0x3737d3a1, 0xfafa401d,
0xc2c2683d, 0xb4b4ccf0, 0x32325dde, 0x9c9c71b3,
0x5656e70b, 0xe3e3da72, 0x878760a7, 0x15151b1c,
0xf9f93aef, 0x6363bfd1, 0x3434a953, 0x9a9a853e,
0xb1b1428f, 0x7c7cd133, 0x88889b26, 0x3d3da65f,
0xa1a1d7ec, 0xe4e4df76, 0x8181942a, 0x91910149,
0x0f0ffb81, 0xeeeeaa88, 0x161661ee, 0xd7d77321,
0x9797f5c4, 0xa5a5a81a, 0xfefe3feb, 0x6d6db5d9,
0x7878aec5, 0xc5c56d39, 0x1d1de599, 0x7676a4cd,
0x3e3edcad, 0xcbcb6731, 0xb6b6478b, 0xefef5b01,
0x12121e18, 0x6060c523, 0x6a6ab0dd, 0x4d4df61f,
0xcecee94e, 0xdede7c2d, 0x55559df9, 0x7e7e5a48,
0x2121b24f, 0x03037af2, 0xa0a02665, 0x5e5e198e,
0x5a5a6678, 0x65654b5c, 0x62624e58, 0xfdfd4519,
0x0606f48d, 0x404086e5, 0xf2f2be98, 0x3333ac57,
0x17179067, 0x05058e7f, 0xe8e85e05, 0x4f4f7d64,
0x89896aaf, 0x10109563, 0x74742fb6, 0x0a0a75fe,
0x5c5c92f5, 0x9b9b74b7, 0x2d2d333c, 0x3030d6a5,
0x2e2e49ce, 0x494989e9, 0x46467268, 0x77775544,
0xa8a8d8e0, 0x9696044d, 0x2828bd43, 0xa9a92969,
0xd9d97929, 0x8686912e, 0xd1d187ac, 0xf4f44a15,
0x8d8d1559, 0xd6d682a8, 0xb9b9bc0a, 0x42420d9e,
0xf6f6c16e, 0x2f2fb847, 0xdddd06df, 0x23233934,
0xcccc6235, 0xf1f1c46a, 0xc1c112cf, 0x8585ebdc,
0x8f8f9e22, 0x7171a1c9, 0x9090f0c0, 0xaaaa539b,
0x0101f189, 0x8b8be1d4, 0x4e4e8ced, 0x8e8e6fab,
0xababa212, 0x6f6f3ea2, 0xe6e6540d, 0xdbdbf252,
0x92927bbb, 0xb7b7b602, 0x6969ca2f, 0x3939d9a9,
0xd3d30cd7, 0xa7a72361, 0xa2a2ad1e, 0xc3c399b4,
0x6c6c4450, 0x07070504, 0x04047ff6, 0x272746c2,
0xacaca716, 0xd0d07625, 0x50501386, 0xdcdcf756,
0x84841a55, 0xe1e15109, 0x7a7a25be, 0x1313ef91
},
{
0xa9d93939, 0x67901717, 0xb3719c9c, 0xe8d2a6a6,
0x04050707, 0xfd985252, 0xa3658080, 0x76dfe4e4,
0x9a084545, 0x92024b4b, 0x80a0e0e0, 0x78665a5a,
0xe4ddafaf, 0xddb06a6a, 0xd1bf6363, 0x38362a2a,
0x0d54e6e6, 0xc6432020, 0x3562cccc, 0x98bef2f2,
0x181e1212, 0xf724ebeb, 0xecd7a1a1, 0x6c774141,
0x43bd2828, 0x7532bcbc, 0x37d47b7b, 0x269b8888,
0xfa700d0d, 0x13f94444, 0x94b1fbfb, 0x485a7e7e,
0xf27a0303, 0xd0e48c8c, 0x8b47b6b6, 0x303c2424,
0x84a5e7e7, 0x54416b6b, 0xdf06dddd, 0x23c56060,
0x1945fdfd, 0x5ba33a3a, 0x3d68c2c2, 0x59158d8d,
0xf321ecec, 0xae316666, 0xa23e6f6f, 0x82165757,
0x63951010, 0x015befef, 0x834db8b8, 0x2e918686,
0xd9b56d6d, 0x511f8383, 0x9b53aaaa, 0x7c635d5d,
0xa63b6868, 0xeb3ffefe, 0xa5d63030, 0xbe257a7a,
0x16a7acac, 0x0c0f0909, 0xe335f0f0, 0x6123a7a7,
0xc0f09090, 0x8cafe9e9, 0x3a809d9d, 0xf5925c5c,
0x73810c0c, 0x2c273131, 0x2576d0d0, 0x0be75656,
0xbb7b9292, 0x4ee9cece, 0x89f10101, 0x6b9f1e1e,
0x53a93434, 0x6ac4f1f1, 0xb499c3c3, 0xf1975b5b,
0xe1834747, 0xe66b1818, 0xbdc82222, 0x450e9898,
0xe26e1f1f, 0xf4c9b3b3, 0xb62f7474, 0x66cbf8f8,
0xccff9999, 0x95ea1414, 0x03ed5858, 0x56f7dcdc,
0xd4e18b8b, 0x1c1b1515, 0x1eada2a2, 0xd70cd3d3,
0xfb2be2e2, 0xc31dc8c8, 0x8e195e5e, 0xb5c22c2c,
0xe9894949, 0xcf12c1c1, 0xbf7e9595, 0xba207d7d,
0xea641111, 0x77840b0b, 0x396dc5c5, 0xaf6a8989,
0x33d17c7c, 0xc9a17171, 0x62ceffff, 0x7137bbbb,
0x81fb0f0f, 0x793db5b5, 0x0951e1e1, 0xaddc3e3e,
0x242d3f3f, 0xcda47676, 0xf99d5555, 0xd8ee8282,
0xe5864040, 0xc5ae7878, 0xb9cd2525, 0x4d049696,
0x44557777, 0x080a0e0e, 0x86135050, 0xe730f7f7,
0xa1d33737, 0x1d40fafa, 0xaa346161, 0xed8c4e4e,
0x06b3b0b0, 0x706c5454, 0xb22a7373, 0xd2523b3b,
0x410b9f9f, 0x7b8b0202, 0xa088d8d8, 0x114ff3f3,
0x3167cbcb, 0xc2462727, 0x27c06767, 0x90b4fcfc,
0x20283838, 0xf67f0404, 0x60784848, 0xff2ee5e5,
0x96074c4c, 0x5c4b6565, 0xb1c72b2b, 0xab6f8e8e,
0x9e0d4242, 0x9cbbf5f5, 0x52f2dbdb, 0x1bf34a4a,
0x5fa63d3d, 0x9359a4a4, 0x0abcb9b9, 0xef3af9f9,
0x91ef1313, 0x85fe0808, 0x49019191, 0xee611616,
0x2d7cdede, 0x4fb22121, 0x8f42b1b1, 0x3bdb7272,
0x47b82f2f, 0x8748bfbf, 0x6d2caeae, 0x46e3c0c0,
0xd6573c3c, 0x3e859a9a, 0x6929a9a9, 0x647d4f4f,
0x2a948181, 0xce492e2e, 0xcb17c6c6, 0x2fca6969,
0xfcc3bdbd, 0x975ca3a3, 0x055ee8e8, 0x7ad0eded,
0xac87d1d1, 0x7f8e0505, 0xd5ba6464, 0x1aa8a5a5,
0x4bb72626, 0x0eb9bebe, 0xa7608787, 0x5af8d5d5,
0x28223636, 0x14111b1b, 0x3fde7575, 0x2979d9d9,
0x88aaeeee, 0x3c332d2d, 0x4c5f7979, 0x02b6b7b7,
0xb896caca, 0xda583535, 0xb09cc4c4, 0x17fc4343,
0x551a8484, 0x1ff64d4d, 0x8a1c5959, 0x7d38b2b2,
0x57ac3333, 0xc718cfcf, 0x8df40606, 0x74695353,
0xb7749b9b, 0xc4f59797, 0x9f56adad, 0x72dae3e3,
0x7ed5eaea, 0x154af4f4, 0x229e8f8f, 0x12a2abab,
0x584e6262, 0x07e85f5f, 0x99e51d1d, 0x34392323,
0x6ec1f6f6, 0x50446c6c, 0xde5d3232, 0x68724646,
0x6526a0a0, 0xbc93cdcd, 0xdb03dada, 0xf8c6baba,
0xc8fa9e9e, 0xa882d6d6, 0x2bcf6e6e, 0x40507070,
0xdceb8585, 0xfe750a0a, 0x328a9393, 0xa48ddfdf,
0xca4c2929, 0x10141c1c, 0x2173d7d7, 0xf0ccb4b4,
0xd309d4d4, 0x5d108a8a, 0x0fe25151, 0x00000000,
0x6f9a1919, 0x9de01a1a, 0x368f9494, 0x42e6c7c7,
0x4aecc9c9, 0x5efdd2d2, 0xc1ab7f7f, 0xe0d8a8a8
},
{
0xbc75bc32, 0xecf3ec21, 0x20c62043, 0xb3f4b3c9,
0xdadbda03, 0x027b028b, 0xe2fbe22b, 0x9ec89efa,
0xc94ac9ec, 0xd4d3d409, 0x18e6186b, 0x1e6b1e9f,
0x9845980e, 0xb27db238, 0xa6e8a6d2, 0x264b26b7,
0x3cd63c57, 0x9332938a, 0x82d882ee, 0x52fd5298,
0x7b377bd4, 0xbb71bb37, 0x5bf15b97, 0x47e14783,
0x2430243c, 0x510f51e2, 0xbaf8bac6, 0x4a1b4af3,
0xbf87bf48, 0x0dfa0d70, 0xb006b0b3, 0x753f75de,
0xd25ed2fd, 0x7dba7d20, 0x66ae6631, 0x3a5b3aa3,
0x598a591c, 0x00000000, 0xcdbccd93, 0x1a9d1ae0,
0xae6dae2c, 0x7fc17fab, 0x2bb12bc7, 0xbe0ebeb9,
0xe080e0a0, 0x8a5d8a10, 0x3bd23b52, 0x64d564ba,
0xd8a0d888, 0xe784e7a5, 0x5f075fe8, 0x1b141b11,
0x2cb52cc2, 0xfc90fcb4, 0x312c3127, 0x80a38065,
0x73b2732a, 0x0c730c81, 0x794c795f, 0x6b546b41,
0x4b924b02, 0x53745369, 0x9436948f, 0x8351831f,
0x2a382a36, 0xc4b0c49c, 0x22bd22c8, 0xd55ad5f8,
0xbdfcbdc3, 0x48604878, 0xff62ffce, 0x4c964c07,
0x416c4177, 0xc742c7e6, 0xebf7eb24, 0x1c101c14,
0x5d7c5d63, 0x36283622, 0x672767c0, 0xe98ce9af,
0x441344f9, 0x149514ea, 0xf59cf5bb, 0xcfc7cf18,
0x3f243f2d, 0xc046c0e3, 0x723b72db, 0x5470546c,
0x29ca294c, 0xf0e3f035, 0x088508fe, 0xc6cbc617,
0xf311f34f, 0x8cd08ce4, 0xa493a459, 0xcab8ca96,
0x68a6683b, 0xb883b84d, 0x38203828, 0xe5ffe52e,
0xad9fad56, 0x0b770b84, 0xc8c3c81d, 0x99cc99ff,
0x580358ed, 0x196f199a, 0x0e080e0a, 0x95bf957e,
0x70407050, 0xf7e7f730, 0x6e2b6ecf, 0x1fe21f6e,
0xb579b53d, 0x090c090f, 0x61aa6134, 0x57825716,
0x9f419f0b, 0x9d3a9d80, 0x11ea1164, 0x25b925cd,
0xafe4afdd, 0x459a4508, 0xdfa4df8d, 0xa397a35c,
0xea7eead5, 0x35da3558, 0xed7aedd0, 0x431743fc,
0xf866f8cb, 0xfb94fbb1, 0x37a137d3, 0xfa1dfa40,
0xc23dc268, 0xb4f0b4cc, 0x32de325d, 0x9cb39c71,
0x560b56e7, 0xe372e3da, 0x87a78760, 0x151c151b,
0xf9eff93a, 0x63d163bf, 0x345334a9, 0x9a3e9a85,
0xb18fb142, 0x7c337cd1, 0x8826889b, 0x3d5f3da6,
0xa1eca1d7, 0xe476e4df, 0x812a8194, 0x91499101,
0x0f810ffb, 0xee88eeaa, 0x16ee1661, 0xd721d773,
0x97c497f5, 0xa51aa5a8, 0xfeebfe3f, 0x6dd96db5,
0x78c578ae, 0xc539c56d, 0x1d991de5, 0x76cd76a4,
0x3ead3edc, 0xcb31cb67, 0xb68bb647, 0xef01ef5b,
0x1218121e, 0x602360c5, 0x6add6ab0, 0x4d1f4df6,
0xce4ecee9, 0xde2dde7c, 0x55f9559d, 0x7e487e5a,
0x214f21b2, 0x03f2037a, 0xa065a026, 0x5e8e5e19,
0x5a785a66, 0x655c654b, 0x6258624e, 0xfd19fd45,
0x068d06f4, 0x40e54086, 0xf298f2be, 0x335733ac,
0x17671790, 0x057f058e, 0xe805e85e, 0x4f644f7d,
0x89af896a, 0x10631095, 0x74b6742f, 0x0afe0a75,
0x5cf55c92, 0x9bb79b74, 0x2d3c2d33, 0x30a530d6,
0x2ece2e49, 0x49e94989, 0x46684672, 0x77447755,
0xa8e0a8d8, 0x964d9604, 0x284328bd, 0xa969a929,
0xd929d979, 0x862e8691, 0xd1acd187, 0xf415f44a,
0x8d598d15, 0xd6a8d682, 0xb90ab9bc, 0x429e420d,
0xf66ef6c1, 0x2f472fb8, 0xdddfdd06, 0x23342339,
0xcc35cc62, 0xf16af1c4, 0xc1cfc112, 0x85dc85eb,
0x8f228f9e, 0x71c971a1, 0x90c090f0, 0xaa9baa53,
0x018901f1, 0x8bd48be1, 0x4eed4e8c, 0x8eab8e6f,
0xab12aba2, 0x6fa26f3e, 0xe60de654, 0xdb52dbf2,
0x92bb927b, 0xb702b7b6, 0x692f69ca, 0x39a939d9,
0xd3d7d30c, 0xa761a723, 0xa21ea2ad, 0xc3b4c399,
0x6c506c44, 0x07040705, 0x04f6047f, 0x27c22746,
0xac16aca7, 0xd025d076, 0x50865013, 0xdc56dcf7,
0x8455841a, 0xe109e151, 0x7abe7a25, 0x139113ef
},
{
0xd939a9d9, 0x90176790, 0x719cb371, 0xd2a6e8d2,
0x05070405, 0x9852fd98, 0x6580a365, 0xdfe476df,
0x08459a08, 0x024b9202, 0xa0e080a0, 0x665a7866,
0xddafe4dd, 0xb06addb0, 0xbf63d1bf, 0x362a3836,
0x54e60d54, 0x4320c643, 0x62cc3562, 0xbef298be,
0x1e12181e, 0x24ebf724, 0xd7a1ecd7, 0x77416c77,
0xbd2843bd, 0x32bc7532, 0xd47b37d4, 0x9b88269b,
0x700dfa70, 0xf94413f9, 0xb1fb94b1, 0x5a7e485a,
0x7a03f27a, 0xe48cd0e4, 0x47b68b47, 0x3c24303c,
0xa5e784a5, 0x416b5441, 0x06dddf06, 0xc56023c5,
0x45fd1945, 0xa33a5ba3, 0x68c23d68, 0x158d5915,
0x21ecf321, 0x3166ae31, 0x3e6fa23e, 0x16578216,
0x95106395, 0x5bef015b, 0x4db8834d, 0x91862e91,
0xb56dd9b5, 0x1f83511f, 0x53aa9b53, 0x635d7c63,
0x3b68a63b, 0x3ffeeb3f, 0xd630a5d6, 0x257abe25,
0xa7ac16a7, 0x0f090c0f, 0x35f0e335, 0x23a76123,
0xf090c0f0, 0xafe98caf, 0x809d3a80, 0x925cf592,
0x810c7381, 0x27312c27, 0x76d02576, 0xe7560be7,
0x7b92bb7b, 0xe9ce4ee9, 0xf10189f1, 0x9f1e6b9f,
0xa93453a9, 0xc4f16ac4, 0x99c3b499, 0x975bf197,
0x8347e183, 0x6b18e66b, 0xc822bdc8, 0x0e98450e,
0x6e1fe26e, 0xc9b3f4c9, 0x2f74b62f, 0xcbf866cb,
0xff99ccff, 0xea1495ea, 0xed5803ed, 0xf7dc56f7,
0xe18bd4e1, 0x1b151c1b, 0xada21ead, 0x0cd3d70c,
0x2be2fb2b, 0x1dc8c31d, 0x195e8e19, 0xc22cb5c2,
0x8949e989, 0x12c1cf12, 0x7e95bf7e, 0x207dba20,
0x6411ea64, 0x840b7784, 0x6dc5396d, 0x6a89af6a,
0xd17c33d1, 0xa171c9a1, 0xceff62ce, 0x37bb7137,
0xfb0f81fb, 0x3db5793d, 0x51e10951, 0xdc3eaddc,
0x2d3f242d, 0xa476cda4, 0x9d55f99d, 0xee82d8ee,
0x8640e586, 0xae78c5ae, 0xcd25b9cd, 0x04964d04,
0x55774455, 0x0a0e080a, 0x13508613, 0x30f7e730,
0xd337a1d3, 0x40fa1d40, 0x3461aa34, 0x8c4eed8c,
0xb3b006b3, 0x6c54706c, 0x2a73b22a, 0x523bd252,
0x0b9f410b, 0x8b027b8b, 0x88d8a088, 0x4ff3114f,
0x67cb3167, 0x4627c246, 0xc06727c0, 0xb4fc90b4,
0x28382028, 0x7f04f67f, 0x78486078, 0x2ee5ff2e,
0x074c9607, 0x4b655c4b, 0xc72bb1c7, 0x6f8eab6f,
0x0d429e0d, 0xbbf59cbb, 0xf2db52f2, 0xf34a1bf3,
0xa63d5fa6, 0x59a49359, 0xbcb90abc, 0x3af9ef3a,
0xef1391ef, 0xfe0885fe, 0x01914901, 0x6116ee61,
0x7cde2d7c, 0xb2214fb2, 0x42b18f42, 0xdb723bdb,
0xb82f47b8, 0x48bf8748, 0x2cae6d2c, 0xe3c046e3,
0x573cd657, 0x859a3e85, 0x29a96929, 0x7d4f647d,
0x94812a94, 0x492ece49, 0x17c6cb17, 0xca692fca,
0xc3bdfcc3, 0x5ca3975c, 0x5ee8055e, 0xd0ed7ad0,
0x87d1ac87, 0x8e057f8e, 0xba64d5ba, 0xa8a51aa8,
0xb7264bb7, 0xb9be0eb9, 0x6087a760, 0xf8d55af8,
0x22362822, 0x111b1411, 0xde753fde, 0x79d92979,
0xaaee88aa, 0x332d3c33, 0x5f794c5f, 0xb6b702b6,
0x96cab896, 0x5835da58, 0x9cc4b09c, 0xfc4317fc,
0x1a84551a, 0xf64d1ff6, 0x1c598a1c, 0x38b27d38,
0xac3357ac, 0x18cfc718, 0xf4068df4, 0x69537469,
0x749bb774, 0xf597c4f5, 0x56ad9f56, 0xdae372da,
0xd5ea7ed5, 0x4af4154a, 0x9e8f229e, 0xa2ab12a2,
0x4e62584e, 0xe85f07e8, 0xe51d99e5, 0x39233439,
0xc1f66ec1, 0x446c5044, 0x5d32de5d, 0x72466872,
0x26a06526, 0x93cdbc93, 0x03dadb03, 0xc6baf8c6,
0xfa9ec8fa, 0x82d6a882, 0xcf6e2bcf, 0x50704050,
0xeb85dceb, 0x750afe75, 0x8a93328a, 0x8ddfa48d,
0x4c29ca4c, 0x141c1014, 0x73d72173, 0xccb4f0cc,
0x09d4d309, 0x108a5d10, 0xe2510fe2, 0x00000000,
0x9a196f9a, 0xe01a9de0, 0x8f94368f, 0xe6c742e6,
0xecc94aec, 0xfdd25efd, 0xab7fc1ab, 0xd8a8e0d8
}
};
} // namespace

View File

@ -0,0 +1,591 @@
/* twofish.cpp
*
* Copyright (C) 2003 Sawtooth Consulting Ltd.
*
* This file is part of yaSSL.
*
* yaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* yaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/* C++ based on Wei Dai's twofish.cpp from CryptoPP */
/* x86 asm original */
#if defined(TAOCRYPT_KERNEL_MODE)
#define DO_TAOCRYPT_KERNEL_MODE
#endif // only some modules now support this
#include "runtime.hpp"
#include "twofish.hpp"
#if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
#define DO_TWOFISH_ASM
#endif
namespace TaoCrypt {
#if !defined(DO_TWOFISH_ASM)
// Generic Version
void Twofish::Process(byte* out, const byte* in, word32 sz)
{
if (mode_ == ECB)
ECB_Process(out, in, sz);
else if (mode_ == CBC)
if (dir_ == ENCRYPTION)
CBC_Encrypt(out, in, sz);
else
CBC_Decrypt(out, in, sz);
}
#else
// ia32 optimized version
void Twofish::Process(byte* out, const byte* in, word32 sz)
{
word32 blocks = sz / BLOCK_SIZE;
if (mode_ == ECB)
while (blocks--) {
if (dir_ == ENCRYPTION)
AsmEncrypt(in, out);
else
AsmDecrypt(in, out);
out += BLOCK_SIZE;
in += BLOCK_SIZE;
}
else if (mode_ == CBC)
if (dir_ == ENCRYPTION)
while (blocks--) {
r_[0] ^= *(word32*)in;
r_[1] ^= *(word32*)(in + 4);
r_[2] ^= *(word32*)(in + 8);
r_[3] ^= *(word32*)(in + 12);
AsmEncrypt((byte*)r_, (byte*)r_);
memcpy(out, r_, BLOCK_SIZE);
out += BLOCK_SIZE;
in += BLOCK_SIZE;
}
else
while (blocks--) {
AsmDecrypt(in, out);
*(word32*)out ^= r_[0];
*(word32*)(out + 4) ^= r_[1];
*(word32*)(out + 8) ^= r_[2];
*(word32*)(out + 12) ^= r_[3];
memcpy(r_, in, BLOCK_SIZE);
out += BLOCK_SIZE;
in += BLOCK_SIZE;
}
}
#endif // DO_TWOFISH_ASM
namespace { // locals
// compute (c * x^4) mod (x^4 + (a + 1/a) * x^3 + a * x^2 + (a + 1/a) * x + 1)
// over GF(256)
static inline unsigned int Mod(unsigned int c)
{
static const unsigned int modulus = 0x14d;
unsigned int c2 = (c<<1) ^ ((c & 0x80) ? modulus : 0);
unsigned int c1 = c2 ^ (c>>1) ^ ((c & 1) ? (modulus>>1) : 0);
return c | (c1 << 8) | (c2 << 16) | (c1 << 24);
}
// compute RS(12,8) code with the above polynomial as generator
// this is equivalent to multiplying by the RS matrix
static word32 ReedSolomon(word32 high, word32 low)
{
for (unsigned int i=0; i<8; i++) {
high = Mod(high>>24) ^ (high<<8) ^ (low>>24);
low <<= 8;
}
return high;
}
} // local namespace
inline word32 Twofish::h0(word32 x, const word32* key, unsigned int kLen)
{
x = x | (x<<8) | (x<<16) | (x<<24);
switch(kLen)
{
#define Q(a, b, c, d, t) q_[a][GETBYTE(t,0)] ^ (q_[b][GETBYTE(t,1)] << 8) ^ \
(q_[c][GETBYTE(t,2)] << 16) ^ (q_[d][GETBYTE(t,3)] << 24)
case 4: x = Q(1, 0, 0, 1, x) ^ key[6];
case 3: x = Q(1, 1, 0, 0, x) ^ key[4];
case 2: x = Q(0, 1, 0, 1, x) ^ key[2];
x = Q(0, 0, 1, 1, x) ^ key[0];
}
return x;
}
inline word32 Twofish::h(word32 x, const word32* key, unsigned int kLen)
{
x = h0(x, key, kLen);
return mds_[0][GETBYTE(x,0)] ^ mds_[1][GETBYTE(x,1)] ^
mds_[2][GETBYTE(x,2)] ^ mds_[3][GETBYTE(x,3)];
}
void Twofish::SetKey(const byte* userKey, word32 keylen, CipherDir /*dummy*/)
{
assert(keylen >= 16 && keylen <= 32);
unsigned int len = (keylen <= 16 ? 2 : (keylen <= 24 ? 3 : 4));
word32 key[8];
GetUserKey(LittleEndianOrder, key, len*2, userKey, keylen);
unsigned int i;
for (i=0; i<40; i+=2) {
word32 a = h(i, key, len);
word32 b = rotlFixed(h(i+1, key+1, len), 8);
k_[i] = a+b;
k_[i+1] = rotlFixed(a+2*b, 9);
}
word32 svec[8];
for (i=0; i<len; i++)
svec[2*(len-i-1)] = ReedSolomon(key[2*i+1], key[2*i]);
for (i=0; i<256; i++) {
word32 t = h0(i, svec, len);
s_[0][i] = mds_[0][GETBYTE(t, 0)];
s_[1][i] = mds_[1][GETBYTE(t, 1)];
s_[2][i] = mds_[2][GETBYTE(t, 2)];
s_[3][i] = mds_[3][GETBYTE(t, 3)];
}
}
void Twofish::ProcessAndXorBlock(const byte* in, const byte* xOr, byte* out)
const
{
if (dir_ == ENCRYPTION)
encrypt(in, xOr, out);
else
decrypt(in, xOr, out);
}
#define G1(x) (s_[0][GETBYTE(x,0)] ^ s_[1][GETBYTE(x,1)] ^ \
s_[2][GETBYTE(x,2)] ^ s_[3][GETBYTE(x,3)])
#define G2(x) (s_[0][GETBYTE(x,3)] ^ s_[1][GETBYTE(x,0)] ^ \
s_[2][GETBYTE(x,1)] ^ s_[3][GETBYTE(x,2)])
#define ENCROUND(n, a, b, c, d) \
x = G1 (a); y = G2 (b); \
x += y; y += x + k[2 * (n) + 1]; \
(c) ^= x + k[2 * (n)]; \
(c) = rotrFixed(c, 1); \
(d) = rotlFixed(d, 1) ^ y
#define ENCCYCLE(n) \
ENCROUND (2 * (n), a, b, c, d); \
ENCROUND (2 * (n) + 1, c, d, a, b)
#define DECROUND(n, a, b, c, d) \
x = G1 (a); y = G2 (b); \
x += y; y += x; \
(d) ^= y + k[2 * (n) + 1]; \
(d) = rotrFixed(d, 1); \
(c) = rotlFixed(c, 1); \
(c) ^= (x + k[2 * (n)])
#define DECCYCLE(n) \
DECROUND (2 * (n) + 1, c, d, a, b); \
DECROUND (2 * (n), a, b, c, d)
typedef BlockGetAndPut<word32, LittleEndian> gpBlock;
void Twofish::encrypt(const byte* inBlock, const byte* xorBlock,
byte* outBlock) const
{
word32 x, y, a, b, c, d;
gpBlock::Get(inBlock)(a)(b)(c)(d);
a ^= k_[0];
b ^= k_[1];
c ^= k_[2];
d ^= k_[3];
const word32 *k = k_+8;
ENCCYCLE (0);
ENCCYCLE (1);
ENCCYCLE (2);
ENCCYCLE (3);
ENCCYCLE (4);
ENCCYCLE (5);
ENCCYCLE (6);
ENCCYCLE (7);
c ^= k_[4];
d ^= k_[5];
a ^= k_[6];
b ^= k_[7];
gpBlock::Put(xorBlock, outBlock)(c)(d)(a)(b);
}
void Twofish::decrypt(const byte* inBlock, const byte* xorBlock,
byte* outBlock) const
{
word32 x, y, a, b, c, d;
gpBlock::Get(inBlock)(c)(d)(a)(b);
c ^= k_[4];
d ^= k_[5];
a ^= k_[6];
b ^= k_[7];
const word32 *k = k_+8;
DECCYCLE (7);
DECCYCLE (6);
DECCYCLE (5);
DECCYCLE (4);
DECCYCLE (3);
DECCYCLE (2);
DECCYCLE (1);
DECCYCLE (0);
a ^= k_[0];
b ^= k_[1];
c ^= k_[2];
d ^= k_[3];
gpBlock::Put(xorBlock, outBlock)(a)(b)(c)(d);
}
#if defined(DO_TWOFISH_ASM)
#ifdef __GNUC__
#define AS1(x) asm(#x);
#define AS2(x, y) asm(#x ", " #y);
#define PROLOG() \
asm(".intel_syntax noprefix"); \
AS2( movd mm3, edi ) \
AS2( movd mm4, ebx ) \
AS2( movd mm5, esi ) \
AS2( movd mm6, ebp ) \
AS2( mov edi, DWORD PTR [ebp + 8] ) \
AS2( mov esi, DWORD PTR [ebp + 12] )
#define EPILOG() \
AS2( movd esp, mm6 ) \
AS2( movd esi, mm5 ) \
AS2( movd ebx, mm4 ) \
AS2( movd edi, mm3 ) \
AS1( emms ) \
asm(".att_syntax");
#else
#define AS1(x) __asm x
#define AS2(x, y) __asm x, y
#define PROLOG() \
AS1( push ebp ) \
AS2( mov ebp, esp ) \
AS2( movd mm3, edi ) \
AS2( movd mm4, ebx ) \
AS2( movd mm5, esi ) \
AS2( movd mm6, ebp ) \
AS2( mov edi, ecx ) \
AS2( mov esi, DWORD PTR [ebp + 8] )
/* ebp already set */
#define EPILOG() \
AS2( movd esi, mm5 ) \
AS2( movd ebx, mm4 ) \
AS2( movd edi, mm3 ) \
AS2( mov esp, ebp ) \
AS1( pop ebp ) \
AS1( emms ) \
AS1( ret 8 )
#endif
// x = esi, y = [esp], s_ = ebp
// edi always open for G1 and G2
// G1 also uses edx after save and restore
// G2 also uses eax after save and restore
// and ecx for tmp [esp] which Rounds also use
// and restore from mm7
// x = G1(a) bytes(0,1,2,3)
#define ASMG1(z, zl, zh) \
AS2( movd mm2, edx ) \
AS2( movzx edi, zl ) \
AS2( mov esi, DWORD PTR [ebp + edi*4] ) \
AS2( movzx edx, zh ) \
AS2( xor esi, DWORD PTR 1024[ebp + edx*4] ) \
\
AS2( mov edx, z ) \
AS2( shr edx, 16 ) \
AS2( movzx edi, dl ) \
AS2( xor esi, DWORD PTR 2048[ebp + edi*4] ) \
AS2( movzx edx, dh ) \
AS2( xor esi, DWORD PTR 3072[ebp + edx*4] ) \
AS2( movd edx, mm2 )
// y = G2(b) bytes(3,0,1,2) [ put y into ecx for Rounds ]
#define ASMG2(z, zl, zh) \
AS2( movd mm7, ecx ) \
AS2( movd mm2, eax ) \
AS2( mov edi, z ) \
AS2( shr edi, 24 ) \
AS2( mov ecx, DWORD PTR [ebp + edi*4] ) \
AS2( movzx eax, zl ) \
AS2( xor ecx, DWORD PTR 1024[ebp + eax*4] ) \
\
AS2( mov eax, z ) \
AS2( shr eax, 16 ) \
AS2( movzx edi, zh ) \
AS2( xor ecx, DWORD PTR 2048[ebp + edi*4] ) \
AS2( movzx eax, al ) \
AS2( xor ecx, DWORD PTR 3072[ebp + eax*4] ) \
AS2( movd eax, mm2 )
// encrypt Round (n),
// x = esi, k = ebp, edi open
// y is in ecx from G2, restore when done from mm7
// before C (which be same register!)
#define ASMENCROUND(N, A, A2, A3, B, B2, B3, C, D) \
/* setup s_ */ \
AS2( movd ebp, mm1 ) \
ASMG1(A, A2, A3) \
ASMG2(B, B2, B3) \
/* setup k */ \
AS2( movd ebp, mm0 ) \
/* x += y */ \
AS2( add esi, ecx ) \
AS2( add ebp, 32 ) \
/* y += x + k[2 * (n) + 1] */ \
AS2( add ecx, esi ) \
AS2( rol D, 1 ) \
AS2( add ecx, DWORD PTR [ebp + 8 * N + 4] ) \
/* (d) = rotlFixed(d, 1) ^ y */ \
AS2( xor D, ecx ) \
AS2( movd ecx, mm7 ) \
/* (c) ^= x + k[2 * (n)] */ \
AS2( mov edi, esi ) \
AS2( add edi, DWORD PTR [ebp + 8 * N] ) \
AS2( xor C, edi ) \
/* (c) = rotrFixed(c, 1) */ \
AS2( ror C, 1 )
// decrypt Round (n),
// x = esi, k = ebp, edi open
// y is in ecx from G2, restore ecx from mm7 when done
#define ASMDECROUND(N, A, A2, A3, B, B2, B3, C, D) \
/* setup s_ */ \
AS2( movd ebp, mm1 ) \
ASMG1(A, A2, A3) \
ASMG2(B, B2, B3) \
/* setup k */ \
AS2( movd ebp, mm0 ) \
/* x += y */ \
AS2( add esi, ecx ) \
AS2( add ebp, 32 ) \
/* y += x */ \
AS2( add ecx, esi ) \
/* (d) ^= y + k[2 * (n) + 1] */ \
AS2( mov edi, DWORD PTR [ebp + 8 * N + 4] ) \
AS2( add edi, ecx ) \
AS2( movd ecx, mm7 ) \
AS2( xor D, edi ) \
/* (d) = rotrFixed(d, 1) */ \
AS2( ror D, 1 ) \
/* (c) = rotlFixed(c, 1) */ \
AS2( rol C, 1 ) \
/* (c) ^= (x + k[2 * (n)]) */ \
AS2( mov edi, esi ) \
AS2( add edi, DWORD PTR [ebp + 8 * N] ) \
AS2( xor C, edi )
#ifdef _MSC_VER
__declspec(naked)
#endif
void Twofish::AsmEncrypt(const byte* inBlock, byte* outBlock) const
{
PROLOG()
#ifdef OLD_GCC_OFFSET
AS2( add edi, 60 ) // k_
#else
AS2( add edi, 56 ) // k_
#endif
AS2( mov ebp, edi )
AS2( mov eax, DWORD PTR [esi] ) // a
AS2( movd mm0, edi ) // store k_
AS2( mov ebx, DWORD PTR [esi + 4] ) // b
AS2( add ebp, 160 ) // s_[0]
AS2( mov ecx, DWORD PTR [esi + 8] ) // c
AS2( movd mm1, ebp ) // store s_
AS2( mov edx, DWORD PTR [esi + 12] ) // d
AS2( xor eax, DWORD PTR [edi] ) // k_[0]
AS2( xor ebx, DWORD PTR [edi + 4] ) // [1]
AS2( xor ecx, DWORD PTR [edi + 8] ) // [2]
AS2( xor edx, DWORD PTR [edi + 12] ) // [3]
ASMENCROUND( 0, eax, al, ah, ebx, bl, bh, ecx, edx)
ASMENCROUND( 1, ecx, cl, ch, edx, dl, dh, eax, ebx)
ASMENCROUND( 2, eax, al, ah, ebx, bl, bh, ecx, edx)
ASMENCROUND( 3, ecx, cl, ch, edx, dl, dh, eax, ebx)
ASMENCROUND( 4, eax, al, ah, ebx, bl, bh, ecx, edx)
ASMENCROUND( 5, ecx, cl, ch, edx, dl, dh, eax, ebx)
ASMENCROUND( 6, eax, al, ah, ebx, bl, bh, ecx, edx)
ASMENCROUND( 7, ecx, cl, ch, edx, dl, dh, eax, ebx)
ASMENCROUND( 8, eax, al, ah, ebx, bl, bh, ecx, edx)
ASMENCROUND( 9, ecx, cl, ch, edx, dl, dh, eax, ebx)
ASMENCROUND(10, eax, al, ah, ebx, bl, bh, ecx, edx)
ASMENCROUND(11, ecx, cl, ch, edx, dl, dh, eax, ebx)
ASMENCROUND(12, eax, al, ah, ebx, bl, bh, ecx, edx)
ASMENCROUND(13, ecx, cl, ch, edx, dl, dh, eax, ebx)
ASMENCROUND(14, eax, al, ah, ebx, bl, bh, ecx, edx)
ASMENCROUND(15, ecx, cl, ch, edx, dl, dh, eax, ebx)
AS2( movd ebp, mm6 )
AS2( movd esi, mm0 ) // k_
#ifdef __GNUC__
AS2( mov edi, [ebp + 16] ) // outBlock
#else
AS2( mov edi, [ebp + 12] ) // outBlock
#endif
AS2( xor ecx, DWORD PTR [esi + 16] ) // k_[4]
AS2( xor edx, DWORD PTR [esi + 20] ) // k_[5]
AS2( xor eax, DWORD PTR [esi + 24] ) // k_[6]
AS2( xor ebx, DWORD PTR [esi + 28] ) // k_[7]
AS2( mov [edi], ecx ) // write out
AS2( mov [edi + 4], edx ) // write out
AS2( mov [edi + 8], eax ) // write out
AS2( mov [edi + 12], ebx ) // write out
EPILOG()
}
#ifdef _MSC_VER
__declspec(naked)
#endif
void Twofish::AsmDecrypt(const byte* inBlock, byte* outBlock) const
{
PROLOG()
#ifdef OLD_GCC_OFFSET
AS2( add edi, 60 ) // k_
#else
AS2( add edi, 56 ) // k_
#endif
AS2( mov ebp, edi )
AS2( mov ecx, DWORD PTR [esi] ) // c
AS2( movd mm0, edi ) // store k_
AS2( mov edx, DWORD PTR [esi + 4] ) // d
AS2( add ebp, 160 ) // s_[0]
AS2( mov eax, DWORD PTR [esi + 8] ) // a
AS2( movd mm1, ebp ) // store s_
AS2( mov ebx, DWORD PTR [esi + 12] ) // b
AS2( xor ecx, DWORD PTR [edi + 16] ) // k_[4]
AS2( xor edx, DWORD PTR [edi + 20] ) // [5]
AS2( xor eax, DWORD PTR [edi + 24] ) // [6]
AS2( xor ebx, DWORD PTR [edi + 28] ) // [7]
ASMDECROUND(15, ecx, cl, ch, edx, dl, dh, eax, ebx)
ASMDECROUND(14, eax, al, ah, ebx, bl, bh, ecx, edx)
ASMDECROUND(13, ecx, cl, ch, edx, dl, dh, eax, ebx)
ASMDECROUND(12, eax, al, ah, ebx, bl, bh, ecx, edx)
ASMDECROUND(11, ecx, cl, ch, edx, dl, dh, eax, ebx)
ASMDECROUND(10, eax, al, ah, ebx, bl, bh, ecx, edx)
ASMDECROUND( 9, ecx, cl, ch, edx, dl, dh, eax, ebx)
ASMDECROUND( 8, eax, al, ah, ebx, bl, bh, ecx, edx)
ASMDECROUND( 7, ecx, cl, ch, edx, dl, dh, eax, ebx)
ASMDECROUND( 6, eax, al, ah, ebx, bl, bh, ecx, edx)
ASMDECROUND( 5, ecx, cl, ch, edx, dl, dh, eax, ebx)
ASMDECROUND( 4, eax, al, ah, ebx, bl, bh, ecx, edx)
ASMDECROUND( 3, ecx, cl, ch, edx, dl, dh, eax, ebx)
ASMDECROUND( 2, eax, al, ah, ebx, bl, bh, ecx, edx)
ASMDECROUND( 1, ecx, cl, ch, edx, dl, dh, eax, ebx)
ASMDECROUND( 0, eax, al, ah, ebx, bl, bh, ecx, edx)
AS2( movd ebp, mm6 )
AS2( movd esi, mm0 ) // k_
#ifdef __GNUC__
AS2( mov edi, [ebp + 16] ) // outBlock
#else
AS2( mov edi, [ebp + 12] ) // outBlock
#endif
AS2( xor eax, DWORD PTR [esi ] ) // k_[0]
AS2( xor ebx, DWORD PTR [esi + 4] ) // k_[1]
AS2( xor ecx, DWORD PTR [esi + 8] ) // k_[2]
AS2( xor edx, DWORD PTR [esi + 12] ) // k_[3]
AS2( mov [edi], eax ) // write out
AS2( mov [edi + 4], ebx ) // write out
AS2( mov [edi + 8], ecx ) // write out
AS2( mov [edi + 12], edx ) // write out
EPILOG()
}
#endif // defined(DO_TWOFISH_ASM)
} // namespace

View File

@ -41,7 +41,7 @@ RSC=rc.exe
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX- /O2 /I "include" /I "..\mySTL" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /G6 /MT /W3 /O2 /I "include" /I "..\mySTL" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
@ -64,7 +64,7 @@ LIB32=link.exe -lib
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX- /ZI /Od /I "include" /I "..\mySTL" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /I "include" /I "..\mySTL" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
@ -105,6 +105,14 @@ SOURCE=.\src\asn.cpp
# End Source File
# Begin Source File
SOURCE=.\src\bftables.cpp
# End Source File
# Begin Source File
SOURCE=.\src\blowfish.cpp
# End Source File
# Begin Source File
SOURCE=.\src\coding.cpp
# End Source File
# Begin Source File
@ -159,6 +167,14 @@ SOURCE=.\src\rsa.cpp
SOURCE=.\src\sha.cpp
# End Source File
# Begin Source File
SOURCE=.\src\tftables.cpp
# End Source File
# Begin Source File
SOURCE=.\src\twofish.cpp
# End Source File
# End Group
# Begin Group "Header Files"
@ -185,6 +201,10 @@ SOURCE=.\include\block.hpp
# End Source File
# Begin Source File
SOURCE=.\include\blowfish.hpp
# End Source File
# Begin Source File
SOURCE=.\include\coding.hpp
# End Source File
# Begin Source File
@ -241,6 +261,10 @@ SOURCE=.\include\modes.hpp
# End Source File
# Begin Source File
SOURCE=.\include\pwdbased.hpp
# End Source File
# Begin Source File
SOURCE=.\include\random.hpp
# End Source File
# Begin Source File
@ -255,6 +279,18 @@ SOURCE=.\include\rsa.hpp
SOURCE=.\include\sha.hpp
# End Source File
# Begin Source File
SOURCE=.\include\twofish.hpp
# End Source File
# Begin Source File
SOURCE=.\include\type_traits.hpp
# End Source File
# Begin Source File
SOURCE=.\include\types.hpp
# End Source File
# End Group
# End Target
# End Project

View File

@ -0,0 +1,102 @@
# Microsoft Developer Studio Project File - Name="test" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=test - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "test.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "test.mak" CFG="test - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "test - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "test - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "test - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "test___Win32_Release"
# PROP BASE Intermediate_Dir "test___Win32_Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "test\Release"
# PROP Intermediate_Dir "test\Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /O2 /I "include" /I "../mySTL" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "test - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "test___Win32_Debug"
# PROP BASE Intermediate_Dir "test___Win32_Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "test\Debug"
# PROP Intermediate_Dir "test\Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /I "include" /I "../mySTL" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "test - Win32 Release"
# Name "test - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\test\test.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

View File

@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "test"=.\test.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@ -0,0 +1,8 @@
INCLUDES = -I../include -I../../mySTL
bin_PROGRAMS = test
test_SOURCES = test.cpp
test_LDFLAGS = -L../src
test_LDADD = -ltaocrypt
test_DEPENDENCIES = ../src/libtaocrypt.la
test_CXXFLAGS = -DYASSL_PURE_C
EXTRA_DIST = make.bat

View File

@ -0,0 +1,9 @@
# quick and dirty build file for testing different MSDEVs
setlocal
set myFLAGS= /I../include /I../../mySTL /c /W3 /G6 /O2
cl %myFLAGS% test.cpp
link.exe /out:test.exe ../src/taocrypt.lib test.obj advapi32.lib

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