Add experimental CMake support

Remove unneeded crypto/aes_via_ace.h

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@270 b624d157-de02-0410-bad0-e51aec6abb33
master
sniperbeamer 16 years ago
parent 25493735fd
commit 74ef78d57e
  1. 96
      CMakeLists.txt
  2. 65
      cmake/FindPCHSupport.cmake
  3. 33
      share/CMakeLists.txt
  4. 172
      src/CMakeLists.txt
  5. 529
      src/crypto/aes_via_ace.h
  6. 1
      src/src.pro

@ -0,0 +1,96 @@
# CMake is still experimental, use qmake instead
PROJECT(KeePassX)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0 FATAL_ERROR)
MESSAGE("CMake is still experimental, use qmake instead")
SET( keepassx_VERSION_SHORT "0.4.0" )
SET( keepassx_VERSION "0.4.0beta1" )
ADD_DEFINITIONS(-D'KEEPASSX_VERSION="${keepassx_VERSION}"')
#Set the custom CMake module directory where our include/lib finders are
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
IF( APPLE OR MINGW )
SET( PROGNAME KeePassX )
ELSE( APPLE OR MINGW )
SET( PROGNAME keepassx )
ENDIF( APPLE OR MINGW )
IF( APPLE )
SET( MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/share/macx_bundle/Info_cmake.plist )
SET( MACOSX_BUNDLE_ICON_FILE ${CMAKE_CURRENT_SOURCE_DIR}/share/macx_bundle/icon.icns )
SET( MACOSX_BUNDLE_INFO_STRING KeePassX v${keepassx_VERSION} )
SET( MACOSX_BUNDLE_VERSION ${keepassx_VERSION} )
SET( MACOSX_BUNDLE_SHORT_VERSION_STRING ${keepassx_VERSION_SHORT} )
SET( MACOSX_BUNDLE_LONG_VERSION_STRING Version ${keepassx_VERSION} )
SET( CMAKE_OSX_ARCHITECTURES ppc;i386 )
ENDIF( APPLE )
IF( MINGW )
FIND_PROGRAM(CMAKE_RC NAMES ${_CMAKE_TOOLCHAIN_PREFIX}windres HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/keepassx.o
COMMAND ${CMAKE_RC} -I${CMAKE_CURRENT_SOURCE_DIR}
-i${CMAKE_CURRENT_SOURCE_DIR}/share/win_ico/keepassx.rc -o ${CMAKE_CURRENT_BINARY_DIR}/keepassx.o )
SET(keepassx_RCS ${CMAKE_CURRENT_BINARY_DIR}/keepassx.o)
ENDIF( MINGW )
OPTION(PRECOMPILED_HEADER "Enable precompiled header (required gcc >= 3.4.0)" TRUE)
IF( APPLE OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD )
SET(PRECOMPILED_HEADER FALSE)
ENDIF( APPLE OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD )
IF( PRECOMPILED_HEADER )
FIND_PACKAGE(PCHSupport)
IF(NOT PCHSupport_FOUND)
SET(PRECOMPILED_HEADER FALSE)
ENDIF(NOT PCHSupport_FOUND)
ENDIF( PRECOMPILED_HEADER )
SET(QT_MIN_VERSION "4.3.0")
SET(QT_USE_QTXML TRUE)
SET(QT_USE_QTMAIN TRUE)
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})
OPTION(AUTOTYPE "Enable auto-type (X11 only)" TRUE)
IF( NOT UNIX )
SET(AUTOTYPE FALSE)
ENDIF( NOT UNIX )
IF( AUTOTYPE )
find_package(X11)
IF( X11_XTest_FOUND )
INCLUDE_DIRECTORIES( ${X11_XTest_INCLUDE_PATH} )
SET(AUTOTYPE_LIBRARIES ${X11_XTest_LIB})
ADD_DEFINITIONS(-DAUTOTYPE -DGLOBAL_AUTOTYPE)
ELSE( X11_XTest_FOUND )
SET(AUTOTYPE FALSE)
ENDIF( X11_XTest_FOUND )
ENDIF( AUTOTYPE )
IF( MINGW )
SET(BINDIR "")
SET(SHAREDIR "share")
ELSEIF( APPLE )
SET(BINDIR "")
SET(SHAREDIR "Contents/Resources")
ELSE( MINGW )
SET(BINDIR "bin")
SET(SHAREDIR "share/keepassx")
SET(SHAREDIR_APP "share")
ENDIF( MINGW )
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(share)

@ -0,0 +1,65 @@
# - Try to find precompiled headers support for GCC 3.4 and 4.x
# Once done this will define:
#
# Variable:
# PCHSupport_FOUND
#
# Macro:
# ADD_PRECOMPILED_HEADER
IF(CMAKE_COMPILER_IS_GNUCXX)
EXEC_PROGRAM(
${CMAKE_CXX_COMPILER}
ARGS --version
OUTPUT_VARIABLE _compiler_output)
STRING(REGEX REPLACE ".* ([0-9]\\.[0-9]\\.[0-9]) .*" "\\1"
gcc_compiler_version ${_compiler_output})
#MESSAGE("GCC Version: ${gcc_compiler_version}")
IF(gcc_compiler_version MATCHES "4\\.[0-9]\\.[0-9]")
SET(PCHSupport_FOUND TRUE)
ELSE(gcc_compiler_version MATCHES "4\\.[0-9]\\.[0-9]")
IF(gcc_compiler_version MATCHES "3\\.4\\.[0-9]")
SET(PCHSupport_FOUND TRUE)
ENDIF(gcc_compiler_version MATCHES "3\\.4\\.[0-9]")
ENDIF(gcc_compiler_version MATCHES "4\\.[0-9]\\.[0-9]")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
MACRO(ADD_PRECOMPILED_HEADER _targetName _input )
GET_FILENAME_COMPONENT(_name ${_input} NAME)
SET(_source "${CMAKE_CURRENT_SOURCE_DIR}/${_input}")
SET(_outdir "${CMAKE_CURRENT_BINARY_DIR}/${_name}.gch")
MAKE_DIRECTORY(${_outdir})
SET(_output "${_outdir}/${CMAKE_BUILD_TYPE}.c++")
STRING(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" _flags_var_name)
SET(_compiler_FLAGS ${${_flags_var_name}})
GET_DIRECTORY_PROPERTY(_directory_flags INCLUDE_DIRECTORIES)
FOREACH(item ${_directory_flags})
LIST(APPEND _compiler_FLAGS "-I${item}")
ENDFOREACH(item)
GET_DIRECTORY_PROPERTY(_directory_flags COMPILE_DEFINITIONS)
FOREACH(item ${_directory_flags})
LIST(APPEND _compiler_FLAGS "-D${item}")
ENDFOREACH(item)
SEPARATE_ARGUMENTS(_compiler_FLAGS)
#MESSAGE("_compiler_FLAGS: ${_compiler_FLAGS}")
message("${CMAKE_CXX_COMPILER} ${_compiler_FLAGS} -x c++-header -o ${_output} ${_source}")
ADD_CUSTOM_COMMAND(
OUTPUT ${_output}
COMMAND ${CMAKE_CXX_COMPILER}
${_compiler_FLAGS}
-x c++-header
-o ${_output} ${_source}
DEPENDS ${_source} )
ADD_CUSTOM_TARGET(${_targetName}_gch DEPENDS ${_output})
ADD_DEPENDENCIES(${_targetName} ${_targetName}_gch)
#SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-include ${_name} -Winvalid-pch -H")
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include ${_name} -Winvalid-pch")
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES
COMPILE_FLAGS "-include ${_name} -Winvalid-pch"
)
ENDMACRO(ADD_PRECOMPILED_HEADER)

@ -0,0 +1,33 @@
# CMake is still experimental, use qmake instead
INSTALL(DIRECTORY keepassx/i18n keepassx/icons
DESTINATION ${SHAREDIR}
PATTERN *.qm EXCLUDE
PATTERN *~ EXCLUDE
PATTERN .svn EXCLUDE
)
INSTALL(FILES keepassx/license.html DESTINATION ${SHAREDIR})
IF (NOT MINGW AND NOT APPLE)
INSTALL(DIRECTORY applications
DESTINATION ${SHAREDIR_APP}
PATTERN *~ EXCLUDE
PATTERN .svn EXCLUDE
)
INSTALL(DIRECTORY mime
DESTINATION ${SHAREDIR_APP}
PATTERN *~ EXCLUDE
PATTERN .svn EXCLUDE
)
INSTALL(DIRECTORY mimelnk
DESTINATION ${SHAREDIR_APP}
PATTERN *~ EXCLUDE
PATTERN .svn EXCLUDE
)
INSTALL(DIRECTORY pixmaps
DESTINATION ${SHAREDIR_APP}
PATTERN *~ EXCLUDE
PATTERN .svn EXCLUDE
)
ENDIF (NOT MINGW AND NOT APPLE)

@ -0,0 +1,172 @@
# CMake is still experimental, use qmake instead
SET(keepassx_HEADERS
main.h
mainwindow.h
Database.h
Kdb3Database.h
lib/EntryView.h
lib/FileDialogs.h
lib/GroupView.h
lib/ShortcutWidget.h
lib/UrlLabel.h
lib/WaitAnimationWidget.h
dialogs/AboutDlg.h
dialogs/AddBookmarkDlg.h
dialogs/CalendarDlg.h
dialogs/CollectEntropyDlg.h
dialogs/CustomizeDetailViewDlg.h
dialogs/DatabaseSettingsDlg.h
dialogs/EditEntryDlg.h
dialogs/EditGroupDlg.h
dialogs/ExpiredEntriesDlg.h
dialogs/ManageBookmarksDlg.h
dialogs/PasswordDlg.h
dialogs/PasswordGenDlg.h
dialogs/SearchDlg.h
dialogs/SelectIconDlg.h
dialogs/SettingsDlg.h
dialogs/SimplePasswordDlg.h
# dialogs/TrashCanDlg.h
import/Import.h
# import/Import_GnuKeyRing.h
import/Import_KeePassX_Xml.h
import/Import_KWalletXml.h
import/Import_PwManager.h
export/Export.h
export/Export_KeePassX_Xml.h
export/Export_Txt.h
)
SET(keepassx_SOURCES
main.cpp
mainwindow.cpp
KpxConfig.cpp
Database.cpp
Kdb3Database.cpp
lib/bookmarks.cpp
lib/EntryView.cpp
lib/FileDialogs.cpp
lib/GroupView.cpp
lib/random.cpp
lib/SecString.cpp
lib/ShortcutWidget.cpp
lib/tools.cpp
lib/UrlLabel.cpp
lib/WaitAnimationWidget.cpp
crypto/aescrypt.c
crypto/aeskey.c
crypto/aes_modes.c
crypto/aestab.c
crypto/arcfour.cpp
crypto/blowfish.cpp
crypto/sha256.cpp
crypto/twoclass.cpp
crypto/twofish.cpp
crypto/yarrow.cpp
apg/convert.c
apg/pronpass.c
apg/randpass.c
dialogs/AboutDlg.cpp
dialogs/AddBookmarkDlg.cpp
dialogs/CalendarDlg.cpp
dialogs/CollectEntropyDlg.cpp
dialogs/CustomizeDetailViewDlg.cpp
dialogs/DatabaseSettingsDlg.cpp
dialogs/EditEntryDlg.cpp
dialogs/EditGroupDlg.cpp
dialogs/ExpiredEntriesDlg.cpp
dialogs/ManageBookmarksDlg.cpp
dialogs/PasswordDlg.cpp
dialogs/PasswordGenDlg.cpp
dialogs/SearchDlg.cpp
dialogs/SelectIconDlg.cpp
dialogs/SettingsDlg.cpp
dialogs/SimplePasswordDlg.cpp
# dialogs/TrashCanDlg.cpp
import/Import.cpp
# import/Import_GnuKeyRing.cpp
import/Import_KeePassX_Xml.cpp
import/Import_KWalletXml.cpp
import/Import_PwManager.cpp
export/Export.cpp
export/Export_KeePassX_Xml.cpp
export/Export_Txt.cpp
)
SET(keepassx_FORMS
forms/AboutDlg.ui
forms/AddBookmarkDlg.ui
forms/CalendarDlg.ui
forms/CollectEntropyDlg.ui
forms/CustomizeDetailViewDlg.ui
forms/DatabaseSettingsDlg.ui
forms/EditEntryDlg.ui
forms/EditGroupDlg.ui
forms/ExpiredEntriesDlg.ui
forms/MainWindow.ui
forms/ManageBookmarksDlg.ui
forms/PasswordDlg.ui
forms/PasswordGenDlg.ui
forms/SearchDlg.ui
forms/SelectIconDlg.ui
forms/SettingsDlg.ui
forms/SimplePasswordDlg.ui
# forms/TrashCanDlg.ui
forms/WorkspaceLockedWidget.ui
)
SET(keepassx_RESOURCES res/resources.qrc)
set(keepassx_TRANSLATIONS
translations/keepassx-cs_CZ.ts
translations/keepassx-de_DE.ts
translations/keepassx-es_ES.ts
translations/keepassx-fr_FR.ts
translations/keepassx-gl_ES.ts
translations/keepassx-it_IT.ts
translations/keepassx-ja_JP.ts
translations/keepassx-ru_RU.ts
)
IF( MINGW )
SET(keepassx_SOURCES ${keepassx_SOURCES} main_win32.cpp)
ELSEIF( APPLE )
SET(keepassx_SOURCES ${keepassx_SOURCES} main_macx.cpp)
ELSE( MINGW )
SET(keepassx_SOURCES ${keepassx_SOURCES} main_unix.cpp)
ENDIF( MINGW )
IF( AUTOTYPE )
SET(keepassx_HEADERS ${keepassx_HEADERS}
Application_X11.h dialogs/AutoTypeDlg.h lib/AutoTypeTreeWidget.h dialogs/TargetWindowDlg.h)
SET(keepassx_SOURCES ${keepassx_SOURCES}
lib/HelperX11.cpp lib/AutoTypeX11.cpp Application_X11.cpp lib/AutoTypeGlobalX11.cpp
dialogs/AutoTypeDlg.cpp lib/AutoTypeTreeWidget.cpp dialogs/TargetWindowDlg.cpp)
SET(keepassx_FORMS ${keepassx_FORMS}
forms/AutoTypeDlg.ui forms/TargetWindowDlg.ui)
ENDIF( AUTOTYPE )
IF( NOT PRECOMPILED_HEADER )
ADD_DEFINITIONS(-include keepassx.h)
ENDIF( NOT PRECOMPILED_HEADER )
INCLUDE_DIRECTORIES(. lib crypto plugins/interfaces export import dialogs ${CMAKE_CURRENT_BINARY_DIR})
QT4_ADD_RESOURCES( keepassx_RESOURCES_SOURCES ${keepassx_RESOURCES} )
QT4_WRAP_UI( keepassx_FORMS_HEADERS ${keepassx_FORMS} )
QT4_WRAP_CPP( keepassx_HEADERS_MOC ${keepassx_HEADERS} )
ADD_EXECUTABLE( ${PROGNAME} WIN32 MACOSX_BUNDLE ${keepassx_SOURCES} ${keepassx_HEADERS_MOC}
${keepassx_RESOURCES_SOURCES} ${keepassx_FORMS_HEADERS} ${keepassx_RCS} )
IF( PRECOMPILED_HEADER )
ADD_PRECOMPILED_HEADER(${PROGNAME} keepassx.h)
ENDIF( PRECOMPILED_HEADER )
TARGET_LINK_LIBRARIES(${PROGNAME} ${QT_LIBRARIES} ${AUTOTYPE_LIBRARIES})
QT4_ADD_TRANSLATION(QM_FILES ${keepassx_TRANSLATIONS})
ADD_CUSTOM_TARGET(translations ALL DEPENDS ${QM_FILES})
INSTALL(TARGETS ${PROGNAME} DESTINATION ${BINDIR})
INSTALL(FILES ${QM_FILES} DESTINATION ${SHAREDIR}/i18n)

@ -1,529 +0,0 @@
/*
---------------------------------------------------------------------------
Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved.
LICENSE TERMS
The redistribution and use of this software (with or without changes)
is allowed without the payment of fees or royalties provided that:
1. source code distributions include the above copyright notice, this
list of conditions and the following disclaimer;
2. binary distributions include the above copyright notice, this list
of conditions and the following disclaimer in their documentation;
3. the name of the copyright holder is not used to endorse products
built using this software without specific written permission.
DISCLAIMER
This software is provided 'as is' with no explicit or implied warranties
in respect of its properties, including, but not limited to, correctness
and/or fitness for purpose.
---------------------------------------------------------------------------
Issue Date: 20/12/20077
*/
#ifndef AES_VIA_ACE_H
#define AES_VIA_ACE_H
#if defined( _MSC_VER )
# define INLINE __inline
#elif defined( __GNUC__ )
# define INLINE static inline
#else
# error VIA ACE requires Microsoft or GNU C
#endif
#define NEH_GENERATE 1
#define NEH_LOAD 2
#define NEH_HYBRID 3
#define MAX_READ_ATTEMPTS 1000
/* VIA Nehemiah RNG and ACE Feature Mask Values */
#define NEH_CPU_IS_VIA 0x00000001
#define NEH_CPU_READ 0x00000010
#define NEH_CPU_MASK 0x00000011
#define NEH_RNG_PRESENT 0x00000004
#define NEH_RNG_ENABLED 0x00000008
#define NEH_ACE_PRESENT 0x00000040
#define NEH_ACE_ENABLED 0x00000080
#define NEH_RNG_FLAGS (NEH_RNG_PRESENT | NEH_RNG_ENABLED)
#define NEH_ACE_FLAGS (NEH_ACE_PRESENT | NEH_ACE_ENABLED)
#define NEH_FLAGS_MASK (NEH_RNG_FLAGS | NEH_ACE_FLAGS)
/* VIA Nehemiah Advanced Cryptography Engine (ACE) Control Word Values */
#define NEH_GEN_KEY 0x00000000 /* generate key schedule */
#define NEH_LOAD_KEY 0x00000080 /* load schedule from memory */
#define NEH_ENCRYPT 0x00000000 /* encryption */
#define NEH_DECRYPT 0x00000200 /* decryption */
#define NEH_KEY128 0x00000000+0x0a /* 128 bit key */
#define NEH_KEY192 0x00000400+0x0c /* 192 bit key */
#define NEH_KEY256 0x00000800+0x0e /* 256 bit key */
#define NEH_ENC_GEN (NEH_ENCRYPT | NEH_GEN_KEY)
#define NEH_DEC_GEN (NEH_DECRYPT | NEH_GEN_KEY)
#define NEH_ENC_LOAD (NEH_ENCRYPT | NEH_LOAD_KEY)
#define NEH_DEC_LOAD (NEH_DECRYPT | NEH_LOAD_KEY)
#define NEH_ENC_GEN_DATA {\
NEH_ENC_GEN | NEH_KEY128, 0, 0, 0,\
NEH_ENC_GEN | NEH_KEY192, 0, 0, 0,\
NEH_ENC_GEN | NEH_KEY256, 0, 0, 0 }
#define NEH_ENC_LOAD_DATA {\
NEH_ENC_LOAD | NEH_KEY128, 0, 0, 0,\
NEH_ENC_LOAD | NEH_KEY192, 0, 0, 0,\
NEH_ENC_LOAD | NEH_KEY256, 0, 0, 0 }
#define NEH_ENC_HYBRID_DATA {\
NEH_ENC_GEN | NEH_KEY128, 0, 0, 0,\
NEH_ENC_LOAD | NEH_KEY192, 0, 0, 0,\
NEH_ENC_LOAD | NEH_KEY256, 0, 0, 0 }
#define NEH_DEC_GEN_DATA {\
NEH_DEC_GEN | NEH_KEY128, 0, 0, 0,\
NEH_DEC_GEN | NEH_KEY192, 0, 0, 0,\
NEH_DEC_GEN | NEH_KEY256, 0, 0, 0 }
#define NEH_DEC_LOAD_DATA {\
NEH_DEC_LOAD | NEH_KEY128, 0, 0, 0,\
NEH_DEC_LOAD | NEH_KEY192, 0, 0, 0,\
NEH_DEC_LOAD | NEH_KEY256, 0, 0, 0 }
#define NEH_DEC_HYBRID_DATA {\
NEH_DEC_GEN | NEH_KEY128, 0, 0, 0,\
NEH_DEC_LOAD | NEH_KEY192, 0, 0, 0,\
NEH_DEC_LOAD | NEH_KEY256, 0, 0, 0 }
#define neh_enc_gen_key(x) ((x) == 128 ? (NEH_ENC_GEN | NEH_KEY128) : \
(x) == 192 ? (NEH_ENC_GEN | NEH_KEY192) : (NEH_ENC_GEN | NEH_KEY256))
#define neh_enc_load_key(x) ((x) == 128 ? (NEH_ENC_LOAD | NEH_KEY128) : \
(x) == 192 ? (NEH_ENC_LOAD | NEH_KEY192) : (NEH_ENC_LOAD | NEH_KEY256))
#define neh_enc_hybrid_key(x) ((x) == 128 ? (NEH_ENC_GEN | NEH_KEY128) : \
(x) == 192 ? (NEH_ENC_LOAD | NEH_KEY192) : (NEH_ENC_LOAD | NEH_KEY256))
#define neh_dec_gen_key(x) ((x) == 128 ? (NEH_DEC_GEN | NEH_KEY128) : \
(x) == 192 ? (NEH_DEC_GEN | NEH_KEY192) : (NEH_DEC_GEN | NEH_KEY256))
#define neh_dec_load_key(x) ((x) == 128 ? (NEH_DEC_LOAD | NEH_KEY128) : \
(x) == 192 ? (NEH_DEC_LOAD | NEH_KEY192) : (NEH_DEC_LOAD | NEH_KEY256))
#define neh_dec_hybrid_key(x) ((x) == 128 ? (NEH_DEC_GEN | NEH_KEY128) : \
(x) == 192 ? (NEH_DEC_LOAD | NEH_KEY192) : (NEH_DEC_LOAD | NEH_KEY256))
#if defined( _MSC_VER ) && ( _MSC_VER > 1200 )
#define aligned_auto(type, name, no, stride) __declspec(align(stride)) type name[no]
#else
#define aligned_auto(type, name, no, stride) \
unsigned char _##name[no * sizeof(type) + stride]; \
type *name = (type*)(16 * ((((unsigned long)(_##name)) + stride - 1) / stride))
#endif
#if defined( _MSC_VER ) && ( _MSC_VER > 1200 )
#define aligned_array(type, name, no, stride) __declspec(align(stride)) type name[no]
#elif defined( __GNUC__ )
#define aligned_array(type, name, no, stride) type name[no] __attribute__ ((aligned(stride)))
#else
#define aligned_array(type, name, no, stride) type name[no]
#endif
/* VIA ACE codeword */
static unsigned char via_flags = 0;
#if defined ( _MSC_VER ) && ( _MSC_VER > 800 )
#define NEH_REKEY __asm pushfd __asm popfd
#define NEH_AES __asm _emit 0xf3 __asm _emit 0x0f __asm _emit 0xa7
#define NEH_ECB NEH_AES __asm _emit 0xc8
#define NEH_CBC NEH_AES __asm _emit 0xd0
#define NEH_CFB NEH_AES __asm _emit 0xe0
#define NEH_OFB NEH_AES __asm _emit 0xe8
#define NEH_RNG __asm _emit 0x0f __asm _emit 0xa7 __asm _emit 0xc0
INLINE int has_cpuid(void)
{ char ret_value;
__asm
{ pushfd /* save EFLAGS register */
mov eax,[esp] /* copy it to eax */
mov edx,0x00200000 /* CPUID bit position */
xor eax,edx /* toggle the CPUID bit */
push eax /* attempt to set EFLAGS to */
popfd /* the new value */
pushfd /* get the new EFLAGS value */
pop eax /* into eax */
xor eax,[esp] /* xor with original value */
and eax,edx /* has CPUID bit changed? */
setne al /* set to 1 if we have been */
mov ret_value,al /* able to change it */
popfd /* restore original EFLAGS */
}
return (int)ret_value;
}
INLINE int is_via_cpu(void)
{ char ret_value;
__asm
{ xor eax,eax /* use CPUID to get vendor */
cpuid /* identity string */
xor eax,eax /* is it "CentaurHauls" ? */
sub ebx,0x746e6543 /* 'Cent' */
or eax,ebx
sub edx,0x48727561 /* 'aurH' */
or eax,edx
sub ecx,0x736c7561 /* 'auls' */
or eax,ecx
sete al /* set to 1 if it is VIA ID */
mov dl,NEH_CPU_READ /* mark CPU type as read */
or dl,al /* & store result in flags */
mov [via_flags],dl /* set VIA detected flag */
mov ret_value,al /* able to change it */
}
return (int)ret_value;
}
INLINE int read_via_flags(void)
{ char ret_value = 0;
__asm
{
mov eax,0xC0000000 /* Centaur extended CPUID */
cpuid
mov edx,0xc0000001 /* >= 0xc0000001 if support */
cmp eax,edx /* for VIA extended feature */
jnae no_rng /* flags is available */
mov eax,edx /* read Centaur extended */
cpuid /* feature flags */
mov eax,NEH_FLAGS_MASK /* mask out and save */
and eax,edx /* the RNG and ACE flags */
or [via_flags],al /* present & enabled flags */
mov ret_value,al /* able to change it */
no_rng:
}
return (int)ret_value;
}
INLINE unsigned int via_rng_in(void *buf)
{ char ret_value = 0x1f;
__asm
{
push edi
mov edi,buf /* input buffer address */
xor edx,edx /* try to fetch 8 bytes */
NEH_RNG /* do RNG read operation */
and ret_value,al /* count of bytes returned */
pop edi
}
return (int)ret_value;
}
INLINE void via_ecb_op5(
const void *k, const void *c, const void *s, void *d, int l)
{ __asm
{
NEH_REKEY
mov ebx, (k)
mov edx, (c)
mov esi, (s)
mov edi, (d)
mov ecx, (l)
NEH_ECB
}
}
INLINE void via_cbc_op6(
const void *k, const void *c, const void *s, void *d, int l, void *v)
{ __asm
{
NEH_REKEY
mov ebx, (k)
mov edx, (c)
mov esi, (s)
mov edi, (d)
mov ecx, (l)
mov eax, (v)
NEH_CBC
}
}
INLINE void via_cbc_op7(
const void *k, const void *c, const void *s, void *d, int l, void *v, void *w)
{ __asm
{
NEH_REKEY
mov ebx, (k)
mov edx, (c)
mov esi, (s)
mov edi, (d)
mov ecx, (l)
mov eax, (v)
NEH_CBC
mov esi, eax
mov edi, (w)
movsd
movsd
movsd
movsd
}
}
INLINE void via_cfb_op6(
const void *k, const void *c, const void *s, void *d, int l, void *v)
{ __asm
{
NEH_REKEY
mov ebx, (k)
mov edx, (c)
mov esi, (s)
mov edi, (d)
mov ecx, (l)
mov eax, (v)
NEH_CFB
}
}
INLINE void via_cfb_op7(
const void *k, const void *c, const void *s, void *d, int l, void *v, void *w)
{ __asm
{
NEH_REKEY
mov ebx, (k)
mov edx, (c)
mov esi, (s)
mov edi, (d)
mov ecx, (l)
mov eax, (v)
NEH_CFB
mov esi, eax
mov edi, (w)
movsd
movsd
movsd
movsd
}
}
INLINE void via_ofb_op6(
const void *k, const void *c, const void *s, void *d, int l, void *v)
{ __asm
{
NEH_REKEY
mov ebx, (k)
mov edx, (c)
mov esi, (s)
mov edi, (d)
mov ecx, (l)
mov eax, (v)
NEH_OFB
}
}
#elif defined( __GNUC__ )
#define NEH_REKEY asm("pushfl\n popfl\n\t")
#define NEH_ECB asm(".byte 0xf3, 0x0f, 0xa7, 0xc8\n\t")
#define NEH_CBC asm(".byte 0xf3, 0x0f, 0xa7, 0xd0\n\t")
#define NEH_CFB asm(".byte 0xf3, 0x0f, 0xa7, 0xe0\n\t")
#define NEH_OFB asm(".byte 0xf3, 0x0f, 0xa7, 0xe8\n\t")
#define NEH_RNG asm(".byte 0x0f, 0xa7, 0xc0\n\t");
INLINE int has_cpuid(void)
{ int val;
asm("pushfl\n\t");
asm("movl 0(%esp),%eax\n\t");
asm("xor $0x00200000,%eax\n\t");
asm("pushl %eax\n\t");
asm("popfl\n\t");
asm("pushfl\n\t");
asm("popl %eax\n\t");
asm("xorl 0(%esp),%edx\n\t");
asm("andl $0x00200000,%eax\n\t");
asm("movl %%eax,%0\n\t" : "=m" (val));
asm("popfl\n\t");
return val ? 1 : 0;
}
INLINE int is_via_cpu(void)
{ int val;
asm("xorl %eax,%eax\n\t");
asm("cpuid\n\t");
asm("xorl %eax,%eax\n\t");
asm("subl $0x746e6543,%ebx\n\t");
asm("orl %ebx,%eax\n\t");
asm("subl $0x48727561,%edx\n\t");
asm("orl %edx,%eax\n\t");
asm("subl $0x736c7561,%ecx\n\t");
asm("orl %ecx,%eax\n\t");
asm("movl %%eax,%0\n\t" : "=m" (val));
val = (val ? 0 : 1);
via_flags = (val | NEH_CPU_READ);
return val;
}
INLINE int read_via_flags(void)
{ unsigned char val;
asm("movl $0xc0000000,%eax\n\t");
asm("cpuid\n\t");
asm("movl $0xc0000001,%edx\n\t");
asm("cmpl %edx,%eax\n\t");
asm("setae %al\n\t");
asm("movb %%al,%0\n\t" : "=m" (val));
if(!val) return 0;
asm("movl $0xc0000001,%eax\n\t");
asm("cpuid\n\t");
asm("movb %%dl,%0\n\t" : "=m" (val));
val &= NEH_FLAGS_MASK;
via_flags |= val;
return (int) val;
}
INLINE int via_rng_in(void *buf)
{ int val;
asm("pushl %edi\n\t");
asm("movl %0,%%edi\n\t" : : "m" (buf));
asm("xorl %edx,%edx\n\t");
NEH_RNG
asm("andl $0x0000001f,%eax\n\t");
asm("movl %%eax,%0\n\t" : "=m" (val));
asm("popl %edi\n\t");
return val;
}
INLINE volatile void via_ecb_op5(
const void *k, const void *c, const void *s, void *d, int l)
{
NEH_REKEY;
asm("movl %0, %%ebx\n\t" : : "m" (k));
asm("movl %0, %%edx\n\t" : : "m" (c));
asm("movl %0, %%esi\n\t" : : "m" (s));
asm("movl %0, %%edi\n\t" : : "m" (d));
asm("movl %0, %%ecx\n\t" : : "m" (l));
NEH_ECB;
}
INLINE volatile void via_cbc_op6(
const void *k, const void *c, const void *s, void *d, int l, void *v)
{
NEH_REKEY;
asm("movl %0, %%ebx\n\t" : : "m" (k));
asm("movl %0, %%edx\n\t" : : "m" (c));
asm("movl %0, %%esi\n\t" : : "m" (s));
asm("movl %0, %%edi\n\t" : : "m" (d));
asm("movl %0, %%ecx\n\t" : : "m" (l));
asm("movl %0, %%eax\n\t" : : "m" (v));
NEH_CBC;
}
INLINE volatile void via_cbc_op7(
const void *k, const void *c, const void *s, void *d, int l, void *v, void *w)
{
NEH_REKEY;
asm("movl %0, %%ebx\n\t" : : "m" (k));
asm("movl %0, %%edx\n\t" : : "m" (c));
asm("movl %0, %%esi\n\t" : : "m" (s));
asm("movl %0, %%edi\n\t" : : "m" (d));
asm("movl %0, %%ecx\n\t" : : "m" (l));
asm("movl %0, %%eax\n\t" : : "m" (v));
NEH_CBC;
asm("movl %eax,%esi\n\t");
asm("movl %0, %%edi\n\t" : : "m" (w));
asm("movsl; movsl; movsl; movsl\n\t");
}
INLINE volatile void via_cfb_op6(
const void *k, const void *c, const void *s, void *d, int l, void *v)
{
NEH_REKEY;
asm("movl %0, %%ebx\n\t" : : "m" (k));
asm("movl %0, %%edx\n\t" : : "m" (c));
asm("movl %0, %%esi\n\t" : : "m" (s));
asm("movl %0, %%edi\n\t" : : "m" (d));
asm("movl %0, %%ecx\n\t" : : "m" (l));
asm("movl %0, %%eax\n\t" : : "m" (v));
NEH_CFB;
}
INLINE volatile void via_cfb_op7(
const void *k, const void *c, const void *s, void *d, int l, void *v, void *w)
{
NEH_REKEY;
asm("movl %0, %%ebx\n\t" : : "m" (k));
asm("movl %0, %%edx\n\t" : : "m" (c));
asm("movl %0, %%esi\n\t" : : "m" (s));
asm("movl %0, %%edi\n\t" : : "m" (d));
asm("movl %0, %%ecx\n\t" : : "m" (l));
asm("movl %0, %%eax\n\t" : : "m" (v));
NEH_CFB;
asm("movl %eax,%esi\n\t");
asm("movl %0, %%edi\n\t" : : "m" (w));
asm("movsl; movsl; movsl; movsl\n\t");
}
INLINE volatile void via_ofb_op6(
const void *k, const void *c, const void *s, void *d, int l, void *v)
{
NEH_REKEY;
asm("movl %0, %%ebx\n\t" : : "m" (k));
asm("movl %0, %%edx\n\t" : : "m" (c));
asm("movl %0, %%esi\n\t" : : "m" (s));
asm("movl %0, %%edi\n\t" : : "m" (d));
asm("movl %0, %%ecx\n\t" : : "m" (l));
asm("movl %0, %%eax\n\t" : : "m" (v));
NEH_OFB;
}
#else
#error VIA ACE is not available with this compiler
#endif
INLINE int via_ace_test(void)
{
return has_cpuid() && is_via_cpu() && ((read_via_flags() & NEH_ACE_FLAGS) == NEH_ACE_FLAGS);
}
#define VIA_ACE_AVAILABLE (((via_flags & NEH_ACE_FLAGS) == NEH_ACE_FLAGS) \
|| (via_flags & NEH_CPU_READ) && (via_flags & NEH_CPU_IS_VIA) || via_ace_test())
INLINE int via_rng_test(void)
{
return has_cpuid() && is_via_cpu() && ((read_via_flags() & NEH_RNG_FLAGS) == NEH_RNG_FLAGS);
}
#define VIA_RNG_AVAILABLE (((via_flags & NEH_RNG_FLAGS) == NEH_RNG_FLAGS) \
|| (via_flags & NEH_CPU_READ) && (via_flags & NEH_CPU_IS_VIA) || via_rng_test())
INLINE int read_via_rng(void *buf, int count)
{ int nbr, max_reads, lcnt = count;
unsigned char *p, *q;
aligned_auto(unsigned char, bp, 64, 16);
if(!VIA_RNG_AVAILABLE)
return 0;
do
{
max_reads = MAX_READ_ATTEMPTS;
do
nbr = via_rng_in(bp);
while
(nbr == 0 && --max_reads);
lcnt -= nbr;
p = (unsigned char*)buf; q = bp;
while(nbr--)
*p++ = *q++;
}
while
(lcnt && max_reads);
return count - lcnt;
}
#endif

@ -176,7 +176,6 @@ HEADERS += main.h \
crypto/aes_types.h \
crypto/aesopt.h \
crypto/aestab.h \
crypto/aes_via_ace.h \
crypto/arcfour.h \
crypto/blowfish.h \
crypto/sha256.h \