Skip to content

Commit

Permalink
Merge pull request softhsm#98 from fxdupont/win14a
Browse files Browse the repository at this point in the history
WIN32 cleanup (updated version)
  • Loading branch information
jschlyter committed Nov 24, 2014
2 parents b88e4e0 + 59f00ad commit 3a2c375
Show file tree
Hide file tree
Showing 94 changed files with 3,144 additions and 3,673 deletions.
58 changes: 50 additions & 8 deletions WIN32-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,60 @@
# WIN32 Specific Notes

Works and checked on Visual Studio 2010 C++ Express, should work with any
Visual Studio 2010 or 2012 Desktop.
Visual Studio 2010, 2012 or 2013 Desktop.

OpenSSL in ssl directory at the same level, Botan in btn, if you want Debug
versions you need ssl+dbg and botand.{lib,dll}. Note openssl.exe should be in
the PATH for cryptotest.exe.
Default locations and names are:
OpenSSL in ssl directory at the same level, Botan in btn, CppUnit in cu,
if you want Debug versions you need ssl_d, btn_d and cu/lib/cppunitd.lib
or cu/cppunitd.lib. You can use the DLL or the static library for
Botan and OpenSSL, if it exists the DLL is copied in the Configuration
(i.e., Release or Debug) directory so is at the same place than
other binaries.

win32+openssl and win32+botan, flags in config.h, solution file in softhsm2.
Configure scripts in win32, same syntax than autotools but without --,
e.g., 'perl Configure.pl with-crypto-backend=botan' (or if you prefer
Python 2 'python Configure.py with-crypto-backend=botan') in a
Visual Studio Command Prompt windows (which is a command.exe windows
where the script <VS>\VC\vcvarsall.bat was invoked).

After you can open the softhsm2.sln file with the Visual Studio GUI
or invoke MSBuild for instance with:
msbuild /t:Build /p:Configuration=Release softhsm2.sln

## Botan build

python configure.py --cpu=x86_32 --cc=msvc --link-mode=copy --prefix=...
options: --cpu=x86_64 --enable-debug --disable-shared
GNU MP: --with-gnump could be fine but GNU MP is not available on WIN32
nmake /f Makefile
nmake /f Makefile check
.\check --validate
name /f Makefile install

## OpenSSL build

perl Configure --prefix=... enable-static-engine VC-WIN32
options: VC-WIN64A debug-VS-WIN*
ms\do_ms (or ms\do_win64a)
nmake /f ms\ntdll.mak (or ms\nt.make)
nmake /f ms\ntdll.mak test
nmake /f ms\ntdll.mak install

## CppUnit build

Get a recent CppUnit distrib, for instance the 1.13.2 version.
Open with the Visual Studio GUI the src\CppUnitLibraries2010.sln solution file.
The interesting project is the cppunit one which builds the needed
cppunit.lib and cppunitd.lib static libraries. Note there is no installation
tool so you have to copy include and library files at the right place
yourselves.

## Project List

- convarch: internal static library
- convarch: internal "convenience" static library
- softhsm2 (main project): softhsm2.dll
- keyconv, util, dump: softhsm2-keyconv.exe, softhsm2-util.exe, and softhsm2-dump-file.exe tools
- keyconv, util, dump: softhsm2-keyconv.exe, softhsm2-util.exe, and
softhsm2-dump-file.exe tools
- p11test, cryptotest, datamgrtest, handlemgrtest, objstoretest,
sessionmgrtest, slotmgrtest: checking tools

Expand All @@ -22,7 +63,8 @@ win32+openssl and win32+botan, flags in config.h, solution file in softhsm2.
- fopen
- getenv
- gmtime
- _snprint
_ _open
- _snprintf (or snprintf on Visual Studio 14)
- sprintf
- sscanf
- strncpy
Expand Down
2 changes: 1 addition & 1 deletion m4/acx_openssl_rfc5649.m4
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ AC_DEFUN([ACX_OPENSSL_EVPAESWRAP],[
AC_MSG_RESULT([RFC 3394 is not supported])
])
AC_MSG_CHECKING(OpenSSL EVP interface for AES key wrapping)
AC_MSG_CHECKING(OpenSSL EVP interface for AES key wrapping with pad)
AC_LINK_IFELSE([
AC_LANG_SOURCE([[
#include <openssl/evp.h>
Expand Down
6 changes: 6 additions & 0 deletions src/bin/keyconv/softhsm2-keyconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
#include <string.h>
#ifndef _WIN32
#include <unistd.h>
#else
#include <io.h>
#define S_IRUSR 0400
#define S_IWUSR 0200
#define open _open
#define close _close
#endif
#include <iostream>
#include <fstream>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/P11Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ CK_RV P11Attribute::retrieve(Token *token, bool isPrivate, CK_VOID_PTR pValue, C
const unsigned char* attrPtr = value.const_byte_str();
memcpy(pValue,attrPtr,attrSize);
}
else
else if (attr.getByteStringValue().size() != 0)
{
const unsigned char* attrPtr = attr.getByteStringValue().const_byte_str();
memcpy(pValue,attrPtr,attrSize);
Expand Down
5 changes: 4 additions & 1 deletion src/lib/SoftHSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2257,7 +2257,10 @@ static CK_RV SymEncryptFinal(Session* session, CK_BYTE_PTR pEncryptedData, CK_UL
return CKR_GENERAL_ERROR;
}

memcpy(pEncryptedData, encryptedFinal.byte_str(), encryptedFinal.size());
if (encryptedFinal.size() != 0)
{
memcpy(pEncryptedData, encryptedFinal.byte_str(), encryptedFinal.size());
}
*pulEncryptedDataLen = encryptedFinal.size();

session->resetOp();
Expand Down
12 changes: 10 additions & 2 deletions src/lib/crypto/BotanDSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ bool BotanDSA::signUpdate(const ByteString& dataToSign)

try
{
signer->update(dataToSign.const_byte_str(), dataToSign.size());
if (dataToSign.size() != 0)
{
signer->update(dataToSign.const_byte_str(),
dataToSign.size());
}
}
catch (...)
{
Expand Down Expand Up @@ -444,7 +448,11 @@ bool BotanDSA::verifyUpdate(const ByteString& originalData)

try
{
verifier->update(originalData.const_byte_str(), originalData.size());
if (originalData.size() != 0)
{
verifier->update(originalData.const_byte_str(),
originalData.size());
}
}
catch (...)
{
Expand Down
12 changes: 10 additions & 2 deletions src/lib/crypto/BotanGOST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ bool BotanGOST::signUpdate(const ByteString& dataToSign)

try
{
signer->update(dataToSign.const_byte_str(), dataToSign.size());
if (dataToSign.size() != 0)
{
signer->update(dataToSign.const_byte_str(),
dataToSign.size());
}
}
catch (...)
{
Expand Down Expand Up @@ -276,7 +280,11 @@ bool BotanGOST::verifyUpdate(const ByteString& originalData)

try
{
verifier->update(originalData.const_byte_str(), originalData.size());
if (originalData.size() != 0)
{
verifier->update(originalData.const_byte_str(),
originalData.size());
}
}
catch (...)
{
Expand Down
5 changes: 4 additions & 1 deletion src/lib/crypto/BotanHashAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ bool BotanHashAlgorithm::hashUpdate(const ByteString& data)
// Continue digesting
try
{
hash->update(data.const_byte_str(), data.size());
if (data.size() != 0)
{
hash->update(data.const_byte_str(), data.size());
}
}
catch (...)
{
Expand Down
12 changes: 10 additions & 2 deletions src/lib/crypto/BotanMacAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ bool BotanMacAlgorithm::signUpdate(const ByteString& dataToSign)

try
{
hmac->update(dataToSign.const_byte_str(), dataToSign.size());
if (dataToSign.size() != 0)
{
hmac->update(dataToSign.const_byte_str(),
dataToSign.size());
}
}
catch (...)
{
Expand Down Expand Up @@ -223,7 +227,11 @@ bool BotanMacAlgorithm::verifyUpdate(const ByteString& originalData)

try
{
hmac->update(originalData.const_byte_str(), originalData.size());
if (originalData.size() != 0)
{
hmac->update(originalData.const_byte_str(),
originalData.size());
}
}
catch (...)
{
Expand Down
12 changes: 10 additions & 2 deletions src/lib/crypto/BotanRSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,11 @@ bool BotanRSA::signUpdate(const ByteString& dataToSign)

try
{
signer->update(dataToSign.const_byte_str(), dataToSign.size());
if (dataToSign.size() != 0)
{
signer->update(dataToSign.const_byte_str(),
dataToSign.size());
}
}
catch (...)
{
Expand Down Expand Up @@ -684,7 +688,11 @@ bool BotanRSA::verifyUpdate(const ByteString& originalData)

try
{
verifier->update(originalData.const_byte_str(), originalData.size());
if (originalData.size() != 0)
{
verifier->update(originalData.const_byte_str(),
originalData.size());
}
}
catch (...)
{
Expand Down
4 changes: 2 additions & 2 deletions src/lib/crypto/BotanSymmetricAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ bool BotanSymmetricAlgorithm::encryptInit(const SymmetricKey* key, const SymMode
try
{
Botan::SymmetricKey botanKey = Botan::SymmetricKey(key->getKeyBits().const_byte_str(), key->getKeyBits().size());
Botan::InitializationVector botanIV = Botan::InitializationVector(IV.const_byte_str(), IV.size());
if (mode == SymMode::ECB)
{
cryption = new Botan::Pipe(Botan::get_cipher(cipherName, botanKey, Botan::ENCRYPTION));
}
else
{
Botan::InitializationVector botanIV = Botan::InitializationVector(IV.const_byte_str(), IV.size());
cryption = new Botan::Pipe(Botan::get_cipher(cipherName, botanKey, botanIV, Botan::ENCRYPTION));
}
cryption->start_msg();
Expand Down Expand Up @@ -273,13 +273,13 @@ bool BotanSymmetricAlgorithm::decryptInit(const SymmetricKey* key, const SymMode
try
{
Botan::SymmetricKey botanKey = Botan::SymmetricKey(key->getKeyBits().const_byte_str(), key->getKeyBits().size());
Botan::InitializationVector botanIV = Botan::InitializationVector(IV.const_byte_str(), IV.size());
if (mode == SymMode::ECB)
{
cryption = new Botan::Pipe(Botan::get_cipher(cipherName, botanKey, Botan::DECRYPTION));
}
else
{
Botan::InitializationVector botanIV = Botan::InitializationVector(IV.const_byte_str(), IV.size());
cryption = new Botan::Pipe(Botan::get_cipher(cipherName, botanKey, botanIV, Botan::DECRYPTION));
}
cryption->start_msg();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/crypto/test/AESTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ void AESTests::testECB()

// Test 128-bit key

// First, use the OpenSSL command line tool to encrypt the test data
// Get the reference for the encrypted data
cipherText = ByteString(testResult[i][j][0]);

// Now, do the same thing using our AES implementation
Expand Down
1 change: 1 addition & 0 deletions src/lib/test/softhsm2.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

directories.tokendir = @builddir@/tokens
objectstore.backend = file
log.level = DEBUG
1 change: 1 addition & 0 deletions src/lib/test/softhsm2.conf.win32
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

directories.tokendir = .\tokens
objectstore.backend = file
log.level = DEBUG
93 changes: 0 additions & 93 deletions win32+botan/slotmgrtest/slotmgrtest.vcxproj

This file was deleted.

Loading

0 comments on commit 3a2c375

Please sign in to comment.