diff --git a/FIPS-NOTES.md b/FIPS-NOTES.md new file mode 100644 index 000000000..1827a3bee --- /dev/null +++ b/FIPS-NOTES.md @@ -0,0 +1,56 @@ +# FIPS 140-2 + +The OpenSSL crypto backend can be a FIPS 140-2 capable library, +cf. the OpenSSL FIPS 140 documents SecurityPolicy and UserGuide. + +## Introduction + +Please read the OpenSSL FIPS 140 documents about to get +a FIPS Capable OpenSSL library. + +## Hard points + +Reread the OpenSSL FIPS 140 documents as they are hard to apply. + +Note the following is for Unix/Linux. + +Now I suppose you have a >= 1.0.1e capable static library (a +dynamic library is far easier but always possible and often +dubious from a security point of view... BTW if you have built +a FIPS Capable OpenSSL library you should not be afraid of +extra complexity :-). + +Do not forget to compile OpenSSL with position indepent code +(aka PIC) as the libsofthsm.so requires it. The FIPS module +canister is already compiled this way. + +A usual issue is the C++ compiler not compiling .c files as C code. +A simple test can show this, put in foo.c file this code: + +foo() { char *x = "ab"; } + +and compile with the C and C++ compilers with all warnings: +the C++ compiler should raise an extra warning or error about +the no type for foo() and/or for the char* string constant. + +When this raises some errors in the fispld script, you have to +insert '-x c' and '-x none' before and after each .c file +in the C++ commands, for instance using this wrapper: + +-------------------------------- cut here -------------------------------- +#!/bin/sh + +commands="g++" + +for elem in $@ +do + case $elem in + *.c) commands+=" -x c $elem -x none";; + *) commands+=" $elem";; + esac +done + +exec $commands +-------------------------------- end -------------------------------- + +In any cases you have to set CC and CXX to fipsld. diff --git a/m4/acx_crypto_backend.m4 b/m4/acx_crypto_backend.m4 index e9ccce784..443a100bd 100644 --- a/m4/acx_crypto_backend.m4 +++ b/m4/acx_crypto_backend.m4 @@ -42,6 +42,28 @@ AC_DEFUN([ACX_CRYPTO_BACKEND],[ fi AM_CONDITIONAL([WITH_GOST], [test "x${enable_gost}" = "xyes"]) + # Second check for the FIPS 140-2 mode + + AC_ARG_ENABLE(fips, + AC_HELP_STRING([--enable-fips], + [Enable support for FIPS 140-2 mode (default disabled)] + ), + [enable_fips="${enableval}"], + [enable_fips="no"] + ) + AC_MSG_CHECKING(for FIPS 140-2 mode) + if test "x${enable_fips}" = "xyes"; then + AC_MSG_RESULT(yes) + AC_DEFINE_UNQUOTED( + [WITH_FIPS], + [], + [Compile with FIPS 140-2 mode] + ) + else + AC_MSG_RESULT(no) + fi + AM_CONDITIONAL([WITH_GOST], [test "x${enable_fips}" = "xyes"]) + # Then check what crypto library we want to use AC_ARG_WITH(crypto-backend, @@ -57,7 +79,11 @@ AC_DEFUN([ACX_CRYPTO_BACKEND],[ if test "x${crypto_backend}" = "xopenssl"; then AC_MSG_RESULT(OpenSSL) - ACX_OPENSSL(1,0,0) + if test "x${enable_fips}" = "xyes"; then + ACX_OPENSSL(1,0,1) + else + ACX_OPENSSL(1,0,0) + fi CRYPTO_INCLUDES=$OPENSSL_INCLUDES CRYPTO_LIBS=$OPENSSL_LIBS @@ -67,10 +93,17 @@ AC_DEFUN([ACX_CRYPTO_BACKEND],[ fi if test "x${enable_gost}" = "xyes"; then + if test "x${enable_fips}" = "xyes"; then + AC_MSG_ERROR([GOST is not FIPS approved]) + fi ACX_OPENSSL_GOST fi - ACX_OPENSSL_EVPAESWRAP + if test "x${enable_fips}" = "xyes"; then + ACX_OPENSSL_FIPS + else + ACX_OPENSSL_EVPAESWRAP + fi AC_DEFINE_UNQUOTED( [WITH_OPENSSL], @@ -90,6 +123,10 @@ AC_DEFUN([ACX_CRYPTO_BACKEND],[ ACX_BOTAN_ECC fi + if test "x${enable_fips}" = "xyes"; then + AC_MSG_ERROR([Botan does not support FIPS 140-2 mode]) + fi + if test "x${enable_gost}" = "xyes"; then ACX_BOTAN_GOST fi diff --git a/m4/acx_openssl_fips.m4 b/m4/acx_openssl_fips.m4 new file mode 100644 index 000000000..a7d9922a7 --- /dev/null +++ b/m4/acx_openssl_fips.m4 @@ -0,0 +1,50 @@ +AC_DEFUN([ACX_OPENSSL_FIPS],[ + AC_MSG_CHECKING(for OpenSSL FIPS capable library) + + tmp_CPPFLAGS=$CPPFLAGS + tmp_LIBS=$LIBS + + CPPFLAGS="$CPPFLAGS $CRYPTO_INCLUDES" + LIBS="$LIBS $CRYPTO_LIBS" + + # check whether we can build an application which can + # "reference the OpenSSL FIPS object module" + + AC_LANG_PUSH([C]) + AC_RUN_IFELSE([ + AC_LANG_SOURCE([[ + #include + int main() + { + return !FIPS_mode_set(1); + } + ]]) + ],[ + AC_MSG_RESULT([Found working FIPS_mode_set()]) + ],[ + AC_MSG_RESULT([FIPS_mode_set(1) failed]) + AC_MSG_ERROR([OpenSSL library is not FIPS capable]) + ],[]) + AC_LANG_POP([C]) + + # build missing fips_premain_dso tool + + if test "x${FIPSLD_CC}" != "x"; then + THERE="`echo $CC | sed -e 's|[[^/]]*$||'`".. + if test "x${FIPSLIBDIR}" != "x"; then + PREMAIN_C="${FIPSLIBDIR}/fips_premain.c" + elif test -f "${THERE}/fips/fips_premain.c"; then + PREMAIN_C="${THERE}/fips/fips_premain.c" + elif test -f "${THERE}/lib/fips_premain.c"; then + PREMAIN_C="${THERE}/lib/fips_premain.c" + else + AC_MSG_WARN([can't find fips_premain.c]) + fi + + $FIPSLD_CC $CPPFLAGS -DFINGERPRINT_PREMAIN_DSO_LOAD \ + -o src/lib/fips_premain_dso $PREMAIN_C $LIBS + fi + + CPPFLAGS=$tmp_CPPFLAGS + LIBS=$tmp_LIBS +]) diff --git a/src/bin/keyconv/softhsm2-keyconv-ossl.cpp b/src/bin/keyconv/softhsm2-keyconv-ossl.cpp index d0ed7fcf2..47671979b 100644 --- a/src/bin/keyconv/softhsm2-keyconv-ossl.cpp +++ b/src/bin/keyconv/softhsm2-keyconv-ossl.cpp @@ -51,6 +51,13 @@ void crypto_init() { OpenSSL_add_all_algorithms(); +#ifdef WITH_FIPS + if (!FIPS_mode_set(1)) + { + fprintf(stderr, "ERROR: can't enter into FIPS mode.\n"); + exit(0); + } +#endif } // Final OpenSSL diff --git a/src/bin/util/softhsm2-util-ossl.cpp b/src/bin/util/softhsm2-util-ossl.cpp index dcb916af3..030e9a7a0 100644 --- a/src/bin/util/softhsm2-util-ossl.cpp +++ b/src/bin/util/softhsm2-util-ossl.cpp @@ -51,6 +51,16 @@ void crypto_init() { // We do not need to do this one // OpenSSL_add_all_algorithms(); +#ifdef WITH_FIPS + // The PKCS#11 library might be using a FIPS capable OpenSSL + if (FIPS_mode()) + return; + if (!FIPS_mode_set(1)) + { + fprintf(stderr, "ERROR: can't enter into FIPS mode.\n"); + exit(0); + } +#endif } // Final OpenSSL diff --git a/src/lib/SoftHSM.cpp b/src/lib/SoftHSM.cpp index f99f4958d..9e7bdf3ad 100644 --- a/src/lib/SoftHSM.cpp +++ b/src/lib/SoftHSM.cpp @@ -416,6 +416,14 @@ CK_RV SoftHSM::C_Initialize(CK_VOID_PTR pInitArgs) return CKR_GENERAL_ERROR; } +#ifdef WITH_FIPS + // Check the FIPS status + if (!CryptoFactory::i()->getFipsSelfTestStatus()) + { + return CKR_FIPS_SELF_TEST_FAILED; + } +#endif + // (Re)load the configuration if (!Configuration::i()->reload(SimpleConfigLoader::i())) { @@ -507,7 +515,11 @@ CK_RV SoftHSM::C_GetInfo(CK_INFO_PTR pInfo) memcpy(pInfo->manufacturerID, "SoftHSM", 7); pInfo->flags = 0; memset(pInfo->libraryDescription, ' ', 32); +#ifdef WITH_FIPS + memcpy(pInfo->libraryDescription, "Implementation of PKCS11+FIPS", 29); +#else memcpy(pInfo->libraryDescription, "Implementation of PKCS11", 24); +#endif pInfo->libraryVersion.major = VERSION_MAJOR; pInfo->libraryVersion.minor = VERSION_MINOR; @@ -564,6 +576,9 @@ CK_RV SoftHSM::C_GetMechanismList(CK_SLOT_ID slotID, CK_MECHANISM_TYPE_PTR pMech #ifdef WITH_ECC nrSupportedMechanisms += 3; #endif +#ifdef WITH_FIPS + nrSupportedMechanisms -= 6; +#endif #ifdef WITH_GOST nrSupportedMechanisms += 5; #endif @@ -572,13 +587,17 @@ CK_RV SoftHSM::C_GetMechanismList(CK_SLOT_ID slotID, CK_MECHANISM_TYPE_PTR pMech #endif CK_MECHANISM_TYPE supportedMechanisms[] = { +#ifndef WITH_FIPS CKM_MD5, +#endif CKM_SHA_1, CKM_SHA224, CKM_SHA256, CKM_SHA384, CKM_SHA512, +#ifndef WITH_FIPS CKM_MD5_HMAC, +#endif CKM_SHA_1_HMAC, CKM_SHA224_HMAC, CKM_SHA256_HMAC, @@ -587,7 +606,9 @@ CK_RV SoftHSM::C_GetMechanismList(CK_SLOT_ID slotID, CK_MECHANISM_TYPE_PTR pMech CKM_RSA_PKCS_KEY_PAIR_GEN, CKM_RSA_PKCS, CKM_RSA_X_509, +#ifndef WITH_FIPS CKM_MD5_RSA_PKCS, +#endif CKM_SHA1_RSA_PKCS, CKM_RSA_PKCS_OAEP, CKM_SHA224_RSA_PKCS, @@ -599,11 +620,15 @@ CK_RV SoftHSM::C_GetMechanismList(CK_SLOT_ID slotID, CK_MECHANISM_TYPE_PTR pMech CKM_SHA256_RSA_PKCS_PSS, CKM_SHA384_RSA_PKCS_PSS, CKM_SHA512_RSA_PKCS_PSS, +#ifndef WITH_FIPS CKM_DES_KEY_GEN, +#endif CKM_DES2_KEY_GEN, CKM_DES3_KEY_GEN, +#ifndef WITH_FIPS CKM_DES_ECB, CKM_DES_CBC, +#endif CKM_DES3_ECB, CKM_DES3_CBC, CKM_AES_KEY_GEN, @@ -766,7 +791,9 @@ CK_RV SoftHSM::C_GetMechanismInfo(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type, CK_ switch (type) { +#ifndef WITH_FIPS case CKM_MD5: +#endif case CKM_SHA_1: case CKM_SHA224: case CKM_SHA256: @@ -777,7 +804,9 @@ CK_RV SoftHSM::C_GetMechanismInfo(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type, CK_ pInfo->ulMaxKeySize = 0; pInfo->flags = CKF_DIGEST; break; +#ifndef WITH_FIPS case CKM_MD5_HMAC: +#endif case CKM_SHA_1_HMAC: case CKM_SHA224_HMAC: case CKM_SHA256_HMAC: @@ -803,7 +832,9 @@ CK_RV SoftHSM::C_GetMechanismInfo(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type, CK_ pInfo->ulMaxKeySize = rsaMaxSize; pInfo->flags = CKF_SIGN | CKF_VERIFY | CKF_ENCRYPT | CKF_DECRYPT; break; +#ifndef WITH_FIPS case CKM_MD5_RSA_PKCS: +#endif case CKM_SHA1_RSA_PKCS: case CKM_SHA224_RSA_PKCS: case CKM_SHA256_RSA_PKCS: @@ -823,7 +854,9 @@ CK_RV SoftHSM::C_GetMechanismInfo(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type, CK_ pInfo->ulMaxKeySize = rsaMaxSize; pInfo->flags = CKF_ENCRYPT | CKF_DECRYPT | CKF_WRAP | CKF_UNWRAP; break; +#ifndef WITH_FIPS case CKM_DES_KEY_GEN: +#endif case CKM_DES2_KEY_GEN: case CKM_DES3_KEY_GEN: // Key size is not in use @@ -831,8 +864,10 @@ CK_RV SoftHSM::C_GetMechanismInfo(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type, CK_ pInfo->ulMaxKeySize = 0; pInfo->flags = CKF_GENERATE; break; +#ifndef WITH_FIPS case CKM_DES_ECB: case CKM_DES_CBC: +#endif case CKM_DES3_ECB: case CKM_DES3_CBC: // Key size is not in use @@ -1809,6 +1844,7 @@ CK_RV SoftHSM::SymEncryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMech ByteString iv; size_t bb = 8; switch(pMechanism->mechanism) { +#ifndef WITH_FIPS case CKM_DES_ECB: algo = SymAlgo::DES; mode = SymMode::ECB; @@ -1827,6 +1863,7 @@ CK_RV SoftHSM::SymEncryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMech memcpy(&iv[0], pMechanism->pParameter, pMechanism->ulParameterLen); bb = 7; break; +#endif case CKM_DES3_ECB: algo = SymAlgo::DES3; mode = SymMode::ECB; @@ -2330,6 +2367,7 @@ CK_RV SoftHSM::SymDecryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMech ByteString iv; size_t bb = 8; switch(pMechanism->mechanism) { +#ifndef WITH_FIPS case CKM_DES_ECB: algo = SymAlgo::DES; mode = SymMode::ECB; @@ -2348,6 +2386,7 @@ CK_RV SoftHSM::SymDecryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMech memcpy(&iv[0], pMechanism->pParameter, pMechanism->ulParameterLen); bb = 7; break; +#endif case CKM_DES3_ECB: algo = SymAlgo::DES3; mode = SymMode::ECB; @@ -2724,9 +2763,11 @@ CK_RV SoftHSM::C_DigestInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechan // Get the mechanism HashAlgo::Type algo = HashAlgo::Unknown; switch(pMechanism->mechanism) { +#ifndef WITH_FIPS case CKM_MD5: algo = HashAlgo::MD5; break; +#endif case CKM_SHA_1: algo = HashAlgo::SHA1; break; @@ -3036,9 +3077,11 @@ CK_RV SoftHSM::MacSignInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechani // Get the MAC algorithm matching the mechanism MacAlgo::Type algo = MacAlgo::Unknown; switch(pMechanism->mechanism) { +#ifndef WITH_FIPS case CKM_MD5_HMAC: algo = MacAlgo::HMAC_MD5; break; +#endif case CKM_SHA_1_HMAC: algo = MacAlgo::HMAC_SHA1; break; @@ -3155,11 +3198,13 @@ CK_RV SoftHSM::AsymSignInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechan bAllowMultiPartOp = false; isRSA = true; break; +#ifndef WITH_FIPS case CKM_MD5_RSA_PKCS: mechanism = AsymMech::RSA_MD5_PKCS; bAllowMultiPartOp = true; isRSA = true; break; +#endif case CKM_SHA1_RSA_PKCS: mechanism = AsymMech::RSA_SHA1_PKCS; bAllowMultiPartOp = true; @@ -3845,9 +3890,11 @@ CK_RV SoftHSM::MacVerifyInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMecha // Get the MAC algorithm matching the mechanism MacAlgo::Type algo = MacAlgo::Unknown; switch(pMechanism->mechanism) { +#ifndef WITH_FIPS case CKM_MD5_HMAC: algo = MacAlgo::HMAC_MD5; break; +#endif case CKM_SHA_1_HMAC: algo = MacAlgo::HMAC_SHA1; break; @@ -3964,11 +4011,13 @@ CK_RV SoftHSM::AsymVerifyInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMech bAllowMultiPartOp = false; isRSA = true; break; +#ifndef WITH_FIPS case CKM_MD5_RSA_PKCS: mechanism = AsymMech::RSA_MD5_PKCS; bAllowMultiPartOp = true; isRSA = true; break; +#endif case CKM_SHA1_RSA_PKCS: mechanism = AsymMech::RSA_SHA1_PKCS; bAllowMultiPartOp = true; @@ -4578,7 +4627,8 @@ CK_RV SoftHSM::C_DigestEncryptUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR /*p // Update a running multi-part decryption and digesting operation CK_RV SoftHSM::C_DecryptDigestUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR /*pPart*/, CK_ULONG /*ulPartLen*/, CK_BYTE_PTR /*pDecryptedPart*/, CK_ULONG_PTR /*pulDecryptedPartLen*/) -{ if (!isInitialised) return CKR_CRYPTOKI_NOT_INITIALIZED; +{ + if (!isInitialised) return CKR_CRYPTOKI_NOT_INITIALIZED; // Get the session Session* session = (Session*)handleManager->getSession(hSession); @@ -4637,10 +4687,12 @@ CK_RV SoftHSM::C_GenerateKey(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMecha objClass = CKO_DOMAIN_PARAMETERS; keyType = CKK_DH; break; +#ifndef WITH_FIPS case CKM_DES_KEY_GEN: objClass = CKO_SECRET_KEY; keyType = CKK_DES; break; +#endif case CKM_DES2_KEY_GEN: objClass = CKO_SECRET_KEY; keyType = CKK_DES2; diff --git a/src/lib/crypto/CryptoFactory.h b/src/lib/crypto/CryptoFactory.h index 2be7c0e4f..761e47329 100644 --- a/src/lib/crypto/CryptoFactory.h +++ b/src/lib/crypto/CryptoFactory.h @@ -51,6 +51,11 @@ class CryptoFactory // This will destroy the one-and-only instance. static void reset(); +#ifdef WITH_FIPS + // Return the FIPS 140-2 selftest status + virtual bool getFipsSelfTestStatus() const = 0; +#endif + // Create a concrete instance of a symmetric algorithm virtual SymmetricAlgorithm* getSymmetricAlgorithm(SymAlgo::Type algorithm) = 0; diff --git a/src/lib/crypto/OSSLCryptoFactory.cpp b/src/lib/crypto/OSSLCryptoFactory.cpp index 21e16bed1..01630d22b 100644 --- a/src/lib/crypto/OSSLCryptoFactory.cpp +++ b/src/lib/crypto/OSSLCryptoFactory.cpp @@ -62,6 +62,7 @@ #include #include #include +#include #ifdef WITH_GOST #include #endif @@ -69,6 +70,11 @@ // Initialise the one-and-only instance std::auto_ptr OSSLCryptoFactory::instance(NULL); +#ifdef WITH_FIPS +// Initialise the FIPS 140-2 selftest status +bool OSSLCryptoFactory::FipsSelfTestStatus = false; +#endif + // Thread ID callback #ifdef HAVE_PTHREAD_H static unsigned long id_callback() @@ -118,6 +124,23 @@ OSSLCryptoFactory::OSSLCryptoFactory() #endif CRYPTO_set_locking_callback(lock_callback); +#ifdef WITH_FIPS + // Already in FIPS mode on reenter (avoiding selftests) + if (!FIPS_mode()) + { + FipsSelfTestStatus = false; + if (!FIPS_mode_set(1)) + { + ERROR_MSG("can't enter into FIPS mode"); + return; + } + } else { + // Undo RAND_cleanup() + RAND_init_fips(); + } + FipsSelfTestStatus = true; +#endif + // Initialise OpenSSL OpenSSL_add_all_algorithms(); @@ -193,6 +216,7 @@ OSSLCryptoFactory::~OSSLCryptoFactory() // Clean up OpenSSL ERR_remove_state(0); + RAND_cleanup(); EVP_cleanup(); CRYPTO_cleanup_all_ex_data(); ERR_free_strings(); @@ -223,6 +247,13 @@ void OSSLCryptoFactory::reset() instance.reset(); } +#ifdef WITH_FIPS +bool OSSLCryptoFactory::getFipsSelfTestStatus() const +{ + return FipsSelfTestStatus; +} +#endif + // Create a concrete instance of a symmetric algorithm SymmetricAlgorithm* OSSLCryptoFactory::getSymmetricAlgorithm(SymAlgo::Type algorithm) { diff --git a/src/lib/crypto/OSSLCryptoFactory.h b/src/lib/crypto/OSSLCryptoFactory.h index ca3c2995a..5b559a00d 100644 --- a/src/lib/crypto/OSSLCryptoFactory.h +++ b/src/lib/crypto/OSSLCryptoFactory.h @@ -55,6 +55,11 @@ class OSSLCryptoFactory : public CryptoFactory // This will destroy the one-and-only instance. static void reset(); +#ifdef WITH_FIPS + // Return the FIPS 140-2 selftest status + virtual bool getFipsSelfTestStatus() const; +#endif + // Create a concrete instance of a symmetric algorithm virtual SymmetricAlgorithm* getSymmetricAlgorithm(SymAlgo::Type algorithm); @@ -85,6 +90,11 @@ class OSSLCryptoFactory : public CryptoFactory // The one-and-only instance static std::auto_ptr instance; +#ifdef WITH_FIPS + // The FIPS 140-2 selftest status + static bool FipsSelfTestStatus; +#endif + // The one-and-only RNG instance RNG* rng; diff --git a/src/lib/crypto/OSSLDES.cpp b/src/lib/crypto/OSSLDES.cpp index ca86567bd..4fb56b5eb 100644 --- a/src/lib/crypto/OSSLDES.cpp +++ b/src/lib/crypto/OSSLDES.cpp @@ -54,7 +54,10 @@ const EVP_CIPHER* OSSLDES::getCipher() const if (currentKey == NULL) return NULL; // Check currentKey bit length; 3DES only supports 56-bit, 112-bit or 168-bit keys - if ((currentKey->getBitLen() != 56) && + if ( +#ifndef WITH_FIPS + (currentKey->getBitLen() != 56) && +#endif (currentKey->getBitLen() != 112) && (currentKey->getBitLen() != 168)) { diff --git a/src/lib/crypto/OSSLDH.cpp b/src/lib/crypto/OSSLDH.cpp index 69a1189e0..1733937ee 100644 --- a/src/lib/crypto/OSSLDH.cpp +++ b/src/lib/crypto/OSSLDH.cpp @@ -227,7 +227,12 @@ bool OSSLDH::deriveKey(SymmetricKey **ppSymmetricKey, PublicKey* publicKey, Priv unsigned long OSSLDH::getMinKeySize() { +#ifdef WITH_FIPS + // OPENSSL_DH_FIPS_MIN_MODULUS_BITS is 1024 + return 1024; +#else return 512; +#endif } unsigned long OSSLDH::getMaxKeySize() diff --git a/src/lib/crypto/OSSLDHPrivateKey.cpp b/src/lib/crypto/OSSLDHPrivateKey.cpp index cbfad59fb..7d43b48fd 100644 --- a/src/lib/crypto/OSSLDHPrivateKey.cpp +++ b/src/lib/crypto/OSSLDHPrivateKey.cpp @@ -44,7 +44,7 @@ OSSLDHPrivateKey::OSSLDHPrivateKey() dh = DH_new(); // Use the OpenSSL implementation and not any engine - DH_set_method(dh, DH_OpenSSL()); + DH_set_method(dh, DH_get_default_method()); } OSSLDHPrivateKey::OSSLDHPrivateKey(const DH* inDH) diff --git a/src/lib/crypto/OSSLDHPublicKey.cpp b/src/lib/crypto/OSSLDHPublicKey.cpp index 61567ae6d..997d6f429 100644 --- a/src/lib/crypto/OSSLDHPublicKey.cpp +++ b/src/lib/crypto/OSSLDHPublicKey.cpp @@ -43,7 +43,7 @@ OSSLDHPublicKey::OSSLDHPublicKey() dh = DH_new(); // Use the OpenSSL implementation and not any engine - DH_set_method(dh, DH_OpenSSL()); + DH_set_method(dh, DH_get_default_method()); } OSSLDHPublicKey::OSSLDHPublicKey(const DH* inDH) diff --git a/src/lib/crypto/OSSLDSA.cpp b/src/lib/crypto/OSSLDSA.cpp index d0b96ecd5..a1bde8d94 100644 --- a/src/lib/crypto/OSSLDSA.cpp +++ b/src/lib/crypto/OSSLDSA.cpp @@ -473,6 +473,9 @@ bool OSSLDSA::generateKeyPair(AsymmetricKeyPair** ppKeyPair, AsymmetricParameter return false; } + // Use the OpenSSL implementation and not any engine + DSA_set_method(dsa, DSA_get_default_method()); + dsa->p = OSSL::byteString2bn(params->getP()); dsa->q = OSSL::byteString2bn(params->getQ()); dsa->g = OSSL::byteString2bn(params->getG()); @@ -502,7 +505,12 @@ bool OSSLDSA::generateKeyPair(AsymmetricKeyPair** ppKeyPair, AsymmetricParameter unsigned long OSSLDSA::getMinKeySize() { +#ifdef WITH_FIPS + // OPENSSL_DSA_FIPS_MIN_MODULUS_BITS is 1024 + return 1024; +#else return 512; +#endif } unsigned long OSSLDSA::getMaxKeySize() diff --git a/src/lib/crypto/OSSLDSAPrivateKey.cpp b/src/lib/crypto/OSSLDSAPrivateKey.cpp index 462462005..06cbc3540 100644 --- a/src/lib/crypto/OSSLDSAPrivateKey.cpp +++ b/src/lib/crypto/OSSLDSAPrivateKey.cpp @@ -44,7 +44,7 @@ OSSLDSAPrivateKey::OSSLDSAPrivateKey() dsa = DSA_new(); // Use the OpenSSL implementation and not any engine - DSA_set_method(dsa, DSA_OpenSSL()); + DSA_set_method(dsa, DSA_get_default_method()); } OSSLDSAPrivateKey::OSSLDSAPrivateKey(const DSA* inDSA) diff --git a/src/lib/crypto/OSSLDSAPublicKey.cpp b/src/lib/crypto/OSSLDSAPublicKey.cpp index fec994599..69c4f2882 100644 --- a/src/lib/crypto/OSSLDSAPublicKey.cpp +++ b/src/lib/crypto/OSSLDSAPublicKey.cpp @@ -43,7 +43,7 @@ OSSLDSAPublicKey::OSSLDSAPublicKey() dsa = DSA_new(); // Use the OpenSSL implementation and not any engine - DSA_set_method(dsa, DSA_OpenSSL()); + DSA_set_method(dsa, DSA_get_default_method()); } OSSLDSAPublicKey::OSSLDSAPublicKey(const DSA* inDSA) diff --git a/src/lib/crypto/OSSLECDH.cpp b/src/lib/crypto/OSSLECDH.cpp index c032cf8d4..2ce64da71 100644 --- a/src/lib/crypto/OSSLECDH.cpp +++ b/src/lib/crypto/OSSLECDH.cpp @@ -184,8 +184,8 @@ bool OSSLECDH::deriveKey(SymmetricKey **ppSymmetricKey, PublicKey* publicKey, Pr } // Use the OpenSSL implementation and not any engine - ECDH_set_method(pub, ECDH_OpenSSL()); - ECDH_set_method(priv, ECDH_OpenSSL()); + ECDH_set_method(pub, ECDH_get_default_method()); + ECDH_set_method(priv, ECDH_get_default_method()); // Derive the secret ByteString secret; diff --git a/src/lib/crypto/OSSLECDSA.cpp b/src/lib/crypto/OSSLECDSA.cpp index 8a86bc519..648e035ae 100644 --- a/src/lib/crypto/OSSLECDSA.cpp +++ b/src/lib/crypto/OSSLECDSA.cpp @@ -74,7 +74,7 @@ bool OSSLECDSA::sign(PrivateKey* privateKey, const ByteString& dataToSign, } // Use the OpenSSL implementation and not any engine - ECDSA_set_method(eckey, ECDSA_OpenSSL()); + ECDSA_set_method(eckey, ECDSA_get_default_method()); // Perform the signature operation size_t len = pk->getOrderLength(); @@ -150,7 +150,7 @@ bool OSSLECDSA::verify(PublicKey* publicKey, const ByteString& originalData, } // Use the OpenSSL implementation and not any engine - ECDSA_set_method(eckey, ECDSA_OpenSSL()); + ECDSA_set_method(eckey, ECDSA_get_default_method()); // Perform the verify operation size_t len = pk->getOrderLength(); diff --git a/src/lib/crypto/OSSLRSA.cpp b/src/lib/crypto/OSSLRSA.cpp index 0c8cb38b2..bad99841f 100644 --- a/src/lib/crypto/OSSLRSA.cpp +++ b/src/lib/crypto/OSSLRSA.cpp @@ -1206,7 +1206,12 @@ bool OSSLRSA::generateKeyPair(AsymmetricKeyPair** ppKeyPair, AsymmetricParameter unsigned long OSSLRSA::getMinKeySize() { +#ifdef WITH_FIPS + // OPENSSL_RSA_FIPS_MIN_MODULUS_BITS is 1024 + return 1024; +#else return 512; +#endif } unsigned long OSSLRSA::getMaxKeySize() diff --git a/src/lib/crypto/OSSLRSAPrivateKey.cpp b/src/lib/crypto/OSSLRSAPrivateKey.cpp index 72575eddc..ba9cf0ea5 100644 --- a/src/lib/crypto/OSSLRSAPrivateKey.cpp +++ b/src/lib/crypto/OSSLRSAPrivateKey.cpp @@ -44,7 +44,7 @@ OSSLRSAPrivateKey::OSSLRSAPrivateKey() rsa = RSA_new(); // Use the OpenSSL implementation and not any engine - RSA_set_method(rsa, RSA_PKCS1_SSLeay()); + RSA_set_method(rsa, RSA_get_default_method()); } OSSLRSAPrivateKey::OSSLRSAPrivateKey(const RSA* inRSA) diff --git a/src/lib/crypto/OSSLRSAPublicKey.cpp b/src/lib/crypto/OSSLRSAPublicKey.cpp index c9c1aadd1..cfb8348cd 100644 --- a/src/lib/crypto/OSSLRSAPublicKey.cpp +++ b/src/lib/crypto/OSSLRSAPublicKey.cpp @@ -34,8 +34,8 @@ #include "log.h" #include "OSSLRSAPublicKey.h" #include "OSSLUtil.h" -#include #include +#include // Constructors OSSLRSAPublicKey::OSSLRSAPublicKey() @@ -43,7 +43,7 @@ OSSLRSAPublicKey::OSSLRSAPublicKey() rsa = RSA_new(); // Use the OpenSSL implementation and not any engine - RSA_set_method(rsa, RSA_PKCS1_SSLeay()); + RSA_set_method(rsa, RSA_get_default_method()); } OSSLRSAPublicKey::OSSLRSAPublicKey(const RSA* inRSA) diff --git a/src/lib/crypto/test/DESTests.cpp b/src/lib/crypto/test/DESTests.cpp index 31561394c..bcb1c6bfb 100644 --- a/src/lib/crypto/test/DESTests.cpp +++ b/src/lib/crypto/test/DESTests.cpp @@ -66,6 +66,7 @@ void DESTests::testBlockSize() void DESTests::testCBC() { +#ifndef WITH_FIPS char testKeys56[][17] = { "0000000000000000", @@ -83,6 +84,7 @@ void DESTests::testCBC() "64398647034486943598534703463870", "87406984068406984607412103517413" }; +#endif char testKeys168[][49] = { @@ -225,17 +227,21 @@ void DESTests::testCBC() for (int i = 0; i < 5; i++) { +#ifndef WITH_FIPS ByteString keyData56(testKeys56[i]); CPPUNIT_ASSERT(keyData56.size() == 8); ByteString keyData112(testKeys112[i]); CPPUNIT_ASSERT(keyData112.size() == 16); +#endif ByteString keyData168(testKeys168[i]); CPPUNIT_ASSERT(keyData168.size() == 24); +#ifndef WITH_FIPS DESKey desKey56(56); CPPUNIT_ASSERT(desKey56.setKeyBits(keyData56)); DESKey desKey112(112); CPPUNIT_ASSERT(desKey112.setKeyBits(keyData112)); +#endif DESKey desKey168(168); CPPUNIT_ASSERT(desKey168.setKeyBits(keyData168)); @@ -247,6 +253,7 @@ void DESTests::testCBC() ByteString cipherText; ByteString shsmCipherText, OB; +#ifndef WITH_FIPS // Test 56-bit key cipherText = ByteString(testResult[i][j][0]); @@ -300,6 +307,7 @@ void DESTests::testCBC() shsmPlainText += OB; CPPUNIT_ASSERT(shsmPlainText == plainText); +#endif // Test 168-bit key cipherText = ByteString(testResult[i][j][2]); @@ -333,6 +341,7 @@ void DESTests::testCBC() void DESTests::testECB() { +#ifndef WITH_FIPS char testKeys56[][17] = { "0000000000000000", @@ -350,6 +359,7 @@ void DESTests::testECB() "64398647034486943598534703463870", "87406984068406984607412103517413" }; +#endif char testKeys168[][49] = { @@ -492,17 +502,21 @@ void DESTests::testECB() for (int i = 0; i < 5; i++) { +#ifndef WITH_FIPS ByteString keyData56(testKeys56[i]); CPPUNIT_ASSERT(keyData56.size() == 8); ByteString keyData112(testKeys112[i]); CPPUNIT_ASSERT(keyData112.size() == 16); +#endif ByteString keyData168(testKeys168[i]); CPPUNIT_ASSERT(keyData168.size() == 24); +#ifndef WITH_FIPS DESKey desKey56(56); CPPUNIT_ASSERT(desKey56.setKeyBits(keyData56)); DESKey desKey112(112); CPPUNIT_ASSERT(desKey112.setKeyBits(keyData112)); +#endif DESKey desKey168(168); CPPUNIT_ASSERT(desKey168.setKeyBits(keyData168)); @@ -514,6 +528,7 @@ void DESTests::testECB() ByteString cipherText; ByteString shsmCipherText, OB; +#ifndef WITH_FIPS // Test 56-bit key cipherText = ByteString(testResult[i][j][0]); @@ -567,6 +582,7 @@ void DESTests::testECB() shsmPlainText += OB; CPPUNIT_ASSERT(shsmPlainText == plainText); +#endif // Test 168-bit key cipherText = ByteString(testResult[i][j][2]); @@ -600,6 +616,7 @@ void DESTests::testECB() void DESTests::testOFB() { +#ifndef WITH_FIPS char testKeys56[][17] = { "0000000000000000", @@ -617,6 +634,7 @@ void DESTests::testOFB() "64398647034486943598534703463870", "87406984068406984607412103517413" }; +#endif char testKeys168[][49] = { @@ -759,17 +777,21 @@ void DESTests::testOFB() for (int i = 0; i < 5; i++) { +#ifndef WITH_FIPS ByteString keyData56(testKeys56[i]); CPPUNIT_ASSERT(keyData56.size() == 8); ByteString keyData112(testKeys112[i]); CPPUNIT_ASSERT(keyData112.size() == 16); +#endif ByteString keyData168(testKeys168[i]); CPPUNIT_ASSERT(keyData168.size() == 24); +#ifndef WITH_FIPS DESKey desKey56(56); CPPUNIT_ASSERT(desKey56.setKeyBits(keyData56)); DESKey desKey112(112); CPPUNIT_ASSERT(desKey112.setKeyBits(keyData112)); +#endif DESKey desKey168(168); CPPUNIT_ASSERT(desKey168.setKeyBits(keyData168)); @@ -781,6 +803,7 @@ void DESTests::testOFB() ByteString cipherText; ByteString shsmCipherText, OB; +#ifndef WITH_FIPS // Test 56-bit key cipherText = ByteString(testResult[i][j][0]); @@ -834,6 +857,7 @@ void DESTests::testOFB() shsmPlainText += OB; CPPUNIT_ASSERT(shsmPlainText == plainText); +#endif // Test 168-bit key cipherText = ByteString(testResult[i][j][2]); @@ -867,6 +891,7 @@ void DESTests::testOFB() void DESTests::testCFB() { +#ifndef WITH_FIPS char testKeys56[][17] = { "0000000000000000", @@ -884,6 +909,7 @@ void DESTests::testCFB() "64398647034486943598534703463870", "87406984068406984607412103517413" }; +#endif char testKeys168[][49] = { @@ -1025,17 +1051,21 @@ void DESTests::testCFB() for (int i = 0; i < 5; i++) { +#ifndef WITH_FIPS ByteString keyData56(testKeys56[i]); CPPUNIT_ASSERT(keyData56.size() == 8); ByteString keyData112(testKeys112[i]); CPPUNIT_ASSERT(keyData112.size() == 16); +#endif ByteString keyData168(testKeys168[i]); CPPUNIT_ASSERT(keyData168.size() == 24); +#ifndef WITH_FIPS DESKey desKey56(56); CPPUNIT_ASSERT(desKey56.setKeyBits(keyData56)); DESKey desKey112(112); CPPUNIT_ASSERT(desKey112.setKeyBits(keyData112)); +#endif DESKey desKey168(168); CPPUNIT_ASSERT(desKey168.setKeyBits(keyData168)); @@ -1047,6 +1077,7 @@ void DESTests::testCFB() ByteString cipherText; ByteString shsmCipherText, OB; +#ifndef WITH_FIPS // Test 56-bit key cipherText = ByteString(testResult[i][j][0]); @@ -1100,6 +1131,7 @@ void DESTests::testCFB() shsmPlainText += OB; CPPUNIT_ASSERT(shsmPlainText == plainText); +#endif // Test 168-bit key cipherText = ByteString(testResult[i][j][2]); diff --git a/src/lib/crypto/test/DHTests.cpp b/src/lib/crypto/test/DHTests.cpp index 9195ae829..3cea4be41 100644 --- a/src/lib/crypto/test/DHTests.cpp +++ b/src/lib/crypto/test/DHTests.cpp @@ -70,9 +70,13 @@ void DHTests::testKeyGeneration() // Key sizes to test std::vector keySizes; +#ifdef WITH_FIPS + keySizes.push_back(1024); +#else keySizes.push_back(512); //keySizes.push_back(768); //keySizes.push_back(1024); +#endif for (std::vector::iterator k = keySizes.begin(); k != keySizes.end(); k++) { @@ -221,9 +225,13 @@ void DHTests::testDerivation() // Key sizes to test std::vector keySizes; +#ifdef WITH_FIPS + keySizes.push_back(1024); +#else keySizes.push_back(512); //keySizes.push_back(768); //keySizes.push_back(1024); +#endif for (std::vector::iterator k = keySizes.begin(); k != keySizes.end(); k++) { diff --git a/src/lib/crypto/test/DSATests.cpp b/src/lib/crypto/test/DSATests.cpp index 3db0148ae..10a7a2097 100644 --- a/src/lib/crypto/test/DSATests.cpp +++ b/src/lib/crypto/test/DSATests.cpp @@ -70,10 +70,14 @@ void DSATests::testKeyGeneration() // Key sizes to test std::vector keySizes; +#ifndef WITH_FIPS keySizes.push_back(512); keySizes.push_back(768); keySizes.push_back(1024); keySizes.push_back(1536); +#else + keySizes.push_back(1024); +#endif #ifndef WITH_BOTAN keySizes.push_back(2048); #endif @@ -201,10 +205,14 @@ void DSATests::testSigningVerifying() // Key sizes to test std::vector keySizes; +#ifndef WITH_FIPS keySizes.push_back(512); keySizes.push_back(768); keySizes.push_back(1024); keySizes.push_back(1536); +#else + keySizes.push_back(1024); +#endif #ifndef WITH_BOTAN keySizes.push_back(2048); #endif diff --git a/src/lib/crypto/test/HashTests.cpp b/src/lib/crypto/test/HashTests.cpp index 3b362a8af..f02adbc09 100644 --- a/src/lib/crypto/test/HashTests.cpp +++ b/src/lib/crypto/test/HashTests.cpp @@ -56,6 +56,7 @@ void HashTests::tearDown() fflush(stdout); } +#ifndef WITH_FIPS void HashTests::testMD5() { char testData[4096] = "EDB39CC3CB5E8FD23A2182FAE8781F4E8E8534C8FE10BDC7ACDB34C4E22E4B60872E51AD092950771E475FB97B05D6203A0D1B3326D9678E44FB40787D8CF16BD3BBE4D4786F60BD8E9766EF1C30B22301FA8F7232358B3C5BE644342499622A5153B29D2E5F8F509771E8A5DE3B3737D30F2AB035262B8D83EC55F683E9B62BBB31E2E1F5E142A13ACB9701E1DE8752ACD492A943C2DB57CF4035BDA9D0519B86847CF74DB2F43CC23016D88EF44BA422710C00AEBB2ABDDED89D92E4BD132CEB87581644198B0D4AF82F3CE161ED03A4E189BE8276243243817F91159BDE294E61400041537618703754C609709846C3EDAE6922B498D24FDC6B9AE702A034BB3A2C6C230E58EE5759DC84AD0B960B111153F6D619E850E36833A26689B4718719EFF3A407B77B0BAD24A17E29B6A29E9125B4CF0DFFEB8D0B03D533ADA43D1F20CFFE0A067E0F6FFF28510148DD72AE33D8B72227523497B84082B682A480FA3B2FE42AAFF49883DAA4DC6826C9593D38002D73FA7AA91B41E828CC34FF12ECC1452B73709696A440CCDF3E6116DA36CB7A01C9E168C3518304721D2CDBC077F4D4B7E8D1A59F954872862F72AC12CB16E33BED8EC3CFD912E36BBF4DA86E31F5F45BE9294550965C7CBC03518AD7C5637A97F7470EDD6E359E82815230CE03AEE9512939A214D017719E5F6B2487E3B468D50DC8EA41EEE94360E77E0EAA9C27DFE2C28D63B7699406E2E6620FE23F96584EEA04034270A2A44096B70017CC2CB197CE8DA3B1924D8D2E86FB40FF59CCFC78B3A4F543068F08C3406DEF52413F95B2BE2AD5DA1ADBB7D95F2133F61AD5518A1BEA018E3C3C0C154EAE56B0B0F4A8818AE47DC618D138245192D055CE4EF8BD1A75030EABAFD66E45B204BA6B123FF54D78F51B6A7DB9B08BEE93E923F9DE553EC0BE4B8BE222998BC792002005ED66C0218902E7DDF6C6D5043A8A9790E438D5BDE37791CDC0DB6C974638884270D4F379DF845281C5F1F8A20978086A9444779D59423B6CEF8175E0BC2C517FA921EC66BE3F11ECEE078553F610D5B65FD293E37717C0CB323A2760646AD56C77A4B96940CF5AD1154A642043E40788C2D367123399FA6015422F5EFEC851EF558ACD4BC31EF3D3EF912241A586E54B97FAE083EE45FBBBED74BC9E3887795FC2EBC5354ACA358EC509F4AB8B2967488D5E5B77DD44EB72E66694A1F490ADEB2848918531B6FA7216C51CDB507598F1AA0985626482D3546BEF5CA3BB409934D11AECBAD47389F2CBCD85FB4DD1A8A6F4D0C28920671A31FFC14FC00FC51296A6182D5A05B16B33232798F0993C78BCC662932E2F57626D639DD00E39B206C1F8A15A19B5DCA9F8B015611AFA47A10A30527F552A22574E15E3577EAD9C7B89782F82D7082D747B50CEFD38C6F17D6269A696F518EE6EAFE1E1EA96FB4D"; @@ -90,6 +91,7 @@ void HashTests::testMD5() hash = NULL; rng = NULL; } +#endif void HashTests::testSHA1() { diff --git a/src/lib/crypto/test/HashTests.h b/src/lib/crypto/test/HashTests.h index 7c277cd9b..dd6566d27 100644 --- a/src/lib/crypto/test/HashTests.h +++ b/src/lib/crypto/test/HashTests.h @@ -40,7 +40,9 @@ class HashTests : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(HashTests); +#ifndef WITH_FIPS CPPUNIT_TEST(testMD5); +#endif CPPUNIT_TEST(testSHA1); CPPUNIT_TEST(testSHA224); CPPUNIT_TEST(testSHA256); @@ -49,7 +51,9 @@ class HashTests : public CppUnit::TestFixture CPPUNIT_TEST_SUITE_END(); public: +#ifndef WITH_FIPS void testMD5(); +#endif void testSHA1(); void testSHA224(); void testSHA256(); diff --git a/src/lib/crypto/test/MacTests.cpp b/src/lib/crypto/test/MacTests.cpp index 19dad8c58..9d6dde4ce 100644 --- a/src/lib/crypto/test/MacTests.cpp +++ b/src/lib/crypto/test/MacTests.cpp @@ -56,6 +56,7 @@ void MacTests::tearDown() fflush(stdout); } +#ifndef WITH_FIPS void MacTests::testHMACMD5() { char testData[4096] = "B64CCFF0DC038F4B4B6C77677B1E89774028CFB6F94EE920ABFABC8C389F7DE287D558664FD05836E854458940A486A367C9B771A7938BE7DFFF2C695BB99CB96F946707FB405A0FA94116FC4002FAD47F813C4DAF6F39B579A2C1E607AF0F80E55FC6742ABB46CF25EFBAEF820DACAE925532E0F2AAAD64D23D0E5682DC38FA47F230EAA299C4D87EB76D45D4B4A08BB47AC873A428708F9D236CF9B11831BC713DB5C8F58A4A4DD228B7A370154CCDB92420B01D0B4141B2CBF05E51D364F7A4D7EE20F1299A697AEAE7341EB6C2F5C458D8AA9A33CE6B2C87B42A9C8EABB3A3311E3828935B8743604895A37D0E9717266872B51CBAB50E9399A0E54457F88DB022CD1859D704FE07C2B530BE14A11072133A9D3A8CD94FCA2B22A320EA08D0292DEADAC4BF705B2CDF71CDC13EC72918F2BD8697BA42AA0AAD62E2D549AC639095EFD2EF606414207CD3770A14FA14AAD7EED197A1A61EBF1FCA89CFE2B69E709C98F4299CF6E1DCF34A98F3C89C6357B5DCDCB335C98EA8DBBA64700EFF9B79CCB875FA49C0C8FA8AA98D6B7B83C3818C4078A8433EEEC71423D9B476029C190ECF1552CF59E1BB2ACDB08663FA792D806E5FF5A6D3E4E09C3F6276663A09D5730A9AAB456D4863F2EDEFEF156A7809AA16D3202AA03C64359BAC628EA1D9ABE2D99999C2891ED49C6081DEA6907C93C5873B4D7880DE271D6016075AFF330FDF221790258A99564F1B51B979DE7997F5FD6676F679B4B14222753547C06960ADCC287EDC29E627FB88BD0E73EBC4E631A58DCA425FADFFEE9DBA177EC182CABA803EEE16636599A88C39A828A5FB206F6DDFD6023F560A421FF3D93B6C4A2A27B78283280C2FD5D249C35270EAE8F8947FA07189BB3A03184C1D8DDB12038184C467EE7DA6CD62F1775F316BE3C2FAB947D49DA19B480E8E4CB4C7818D7769351107386311E5EE411DAC5136869C147DA8E782FA60ED69B13C2DE18CF11FD75CE5F8F16993A026FC3441EE3B23DD6002B8F015E5CC336B5559A427864338C098F4857AA40399916614E061BB176AE4457CA72625A37F08F179A14C39B065CF3283E9425355B6504784C0F4FC1D7932F5C14B43A9CE3604935DE695CDB60B1ED58BD71AB540EEDDF9337B0743D8E624E1A932A69FB1FCA21CFE7F6D2FFDA78F2B8D5BCE01C59BC0A3981BB3BBECF345F43ACD571432B742F80491B490FD71F947480FF9D215EC21237F5AF28C31608DA7A6230CAD24EA799506C8C0B1298E9FD09DA496C6B63710920CC0DC14C00944A7D9B9B751D741A828AB35A5926D3653D45531A4D233DE198439D1946633FF6B91DF0744073CC6E3EC3B177414D8ED2AF30515D8688914667F507667776634A2A11BB68F65B363BD56E8CCF957EB4BB0147862D4C17268AFCE5685C8346E1917B8E8618D3888355CE401AAC5D2DF"; @@ -96,6 +97,7 @@ void MacTests::testHMACMD5() mac = NULL; rng = NULL; } +#endif void MacTests::testHMACSHA1() { diff --git a/src/lib/crypto/test/MacTests.h b/src/lib/crypto/test/MacTests.h index 912186a42..b8ec2adf9 100644 --- a/src/lib/crypto/test/MacTests.h +++ b/src/lib/crypto/test/MacTests.h @@ -40,7 +40,9 @@ class MacTests : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(MacTests); +#ifndef WITH_FIPS CPPUNIT_TEST(testHMACMD5); +#endif CPPUNIT_TEST(testHMACSHA1); CPPUNIT_TEST(testHMACSHA224); CPPUNIT_TEST(testHMACSHA256); @@ -49,7 +51,9 @@ class MacTests : public CppUnit::TestFixture CPPUNIT_TEST_SUITE_END(); public: +#ifndef WITH_FIPS void testHMACMD5(); +#endif void testHMACSHA1(); void testHMACSHA224(); void testHMACSHA256(); diff --git a/src/lib/crypto/test/RSATests.cpp b/src/lib/crypto/test/RSATests.cpp index f17a92137..9ac5b26f6 100644 --- a/src/lib/crypto/test/RSATests.cpp +++ b/src/lib/crypto/test/RSATests.cpp @@ -79,7 +79,9 @@ void RSATests::testKeyGeneration() // Key sizes to test std::vector keySizes; keySizes.push_back(1024); +#ifndef WITH_FIPS keySizes.push_back(1025); +#endif keySizes.push_back(1280); keySizes.push_back(2048); //keySizes.push_back(4096); @@ -258,7 +260,9 @@ void RSATests::testSigningVerifying() // Mechanisms to test std::vector mechanisms; +#ifndef WITH_FIPS mechanisms.push_back(AsymMech::RSA_MD5_PKCS); +#endif mechanisms.push_back(AsymMech::RSA_SHA1_PKCS); mechanisms.push_back(AsymMech::RSA_SHA224_PKCS); mechanisms.push_back(AsymMech::RSA_SHA256_PKCS); @@ -269,7 +273,9 @@ void RSATests::testSigningVerifying() mechanisms.push_back(AsymMech::RSA_SHA256_PKCS_PSS); mechanisms.push_back(AsymMech::RSA_SHA384_PKCS_PSS); mechanisms.push_back(AsymMech::RSA_SHA512_PKCS_PSS); +#ifndef WITH_FIPS mechanisms.push_back(AsymMech::RSA_SSL); +#endif /* Max salt length for SHA512 and 1024-bit RSA is 62 bytes */ RSA_PKCS_PSS_PARAMS pssParams[] = { @@ -400,13 +406,20 @@ void RSATests::testSignVerifyKnownVector() // These test vectors were taken from the Crypto++ set of test vectors // Crypto++ can be downloaded from www.cryptopp.com +#ifndef WITH_FIPS RSAPublicKey* pubKey1 = (RSAPublicKey*) rsa->newPublicKey(); RSAPublicKey* pubKey2 = (RSAPublicKey*) rsa->newPublicKey(); +#endif + RSAPublicKey* pubKey3 = (RSAPublicKey*) rsa->newPublicKey(); +#ifndef WITH_FIPS RSAPrivateKey* privKey1_1 = (RSAPrivateKey*) rsa->newPrivateKey(); RSAPrivateKey* privKey1_2 = (RSAPrivateKey*) rsa->newPrivateKey(); RSAPrivateKey* privKey2_1 = (RSAPrivateKey*) rsa->newPrivateKey(); RSAPrivateKey* privKey2_2 = (RSAPrivateKey*) rsa->newPrivateKey(); +#endif + RSAPrivateKey* privKey3 = (RSAPrivateKey*) rsa->newPrivateKey(); +#ifndef WITH_FIPS // Reconstruct public and private key #1 ByteString n1 = "0A66791DC6988168DE7AB77419BB7FB0C001C62710270075142942E19A8D8C51D053B3E3782A1DE5DC5AF4EBE99468170114A1DFE67CDC9A9AF55D655620BBAB"; ByteString e1 = "010001"; @@ -458,7 +471,23 @@ void RSATests::testSignVerifyKnownVector() privKey2_2->setN(n2); privKey2_2->setE(e2); privKey2_2->setD(d2); +#endif + ByteString n3 = "A8D68ACD413C5E195D5EF04E1B4FAAF242365CB450196755E92E1215BA59802AAFBADBF2564DD550956ABB54F8B1C917844E5F36195D1088C600E07CADA5C080EDE679F50B3DE32CF4026E514542495C54B1903768791AAE9E36F082CD38E941ADA89BAECADA61AB0DD37AD536BCB0A0946271594836E92AB5517301D45176B5"; + ByteString e3 = "03"; + ByteString d3 = "1C23C1CCE034BA598F8FD2B7AF37F1D30B090F7362AEE68E5187ADAE49B9955C729F24A863B7A38D6E3C748E2972F6D940B7BA89043A2D6C2100256A1CF0F56A8CD35FC6EE205244876642F6F9C3820A3D9D2C8921DF7D82AAADCAF2D7334D398931DDBBA553190B3A416099F3AA07FD5B26214645A828419E122CFB857AD73B"; + ByteString p3 = "C107a2fe924b76e206cb9bc4af2ab7008547c00846bf6d0680b3eac3ebcbd0c7fd7a54c2b9899b08f80cde1d3691eaaa2816b1eb11822d6be7beaf4e30977c49"; + ByteString q3 = "DFEA984CE4307EAFC0D140C2BB82861E5DBAC4F8567CBC981D70440DD639492079031486315E305EB83E591C4A2E96064966F7C894C3CA351925B5CE82D8EF0D"; + + pubKey3->setN(n3); + pubKey3->setE(e3); + privKey3->setN(n3); + privKey3->setE(e3); + privKey3->setD(d3); + privKey3->setP(p3); + privKey3->setQ(q3); + +#ifndef WITH_FIPS // Test with key #1 const char* testValue1 = "Everyone gets Friday off."; @@ -510,13 +539,35 @@ void RSATests::testSignVerifyKnownVector() CPPUNIT_ASSERT(rsa->verifyInit(pubKey2, AsymMech::RSA_SHA1_PKCS)); CPPUNIT_ASSERT(rsa->verifyUpdate(dataToSign2)); CPPUNIT_ASSERT(rsa->verifyFinal(expectedSignature2)); +#endif + // Test with key #3 + ByteString dataToSign3 = "D73829497CDDBE41B705FAAC50E7899FDB5A38BF3A459E536357029E64F8796BA47F4FE96BA5A8B9A4396746E2164F55A25368DDD0B9A5188C7AC3DA2D1F742286C3BDEE697F9D546A25EFCFE53191D743FCC6B47833D993D08804DAECA78FB9076C3C017F53E33A90305AF06220974D46BF19ED3C9B84EDBAE98B45A8771258"; + ByteString expectedSignature3 = "175015BDA50ABE0FA7D39A8353885CA01BE3A7E7FCC55045744111362EE1914473A48DC537D956294B9E20A1EF661D58537ACDC8DE908FA050630FCC272E6D001045E6FDEED2D10531C8603334C2E8DB39E73E6D9665EE1343F9E4198302D2201B44E8E8D06B3EF49CEE6197582163A8490089CA654C0012FCE1BA6511089750"; + ByteString signature3; + + CPPUNIT_ASSERT(rsa->signInit(privKey3, AsymMech::RSA_SHA1_PKCS)); + CPPUNIT_ASSERT(rsa->signUpdate(dataToSign3)); + CPPUNIT_ASSERT(rsa->signFinal(signature3)); + + CPPUNIT_ASSERT(signature3 == expectedSignature3); + + CPPUNIT_ASSERT(rsa->verifyInit(pubKey3, AsymMech::RSA_SHA1_PKCS)); + CPPUNIT_ASSERT(rsa->verifyUpdate(dataToSign3)); + CPPUNIT_ASSERT(rsa->verifyFinal(expectedSignature3)); + +#ifndef WITH_FIPS rsa->recyclePublicKey(pubKey1); rsa->recyclePublicKey(pubKey2); +#endif + rsa->recyclePublicKey(pubKey3); +#ifndef WITH_FIPS rsa->recyclePrivateKey(privKey1_1); rsa->recyclePrivateKey(privKey1_2); rsa->recyclePrivateKey(privKey2_1); rsa->recyclePrivateKey(privKey2_2); +#endif + rsa->recyclePrivateKey(privKey3); } void RSATests::testEncryptDecrypt() diff --git a/src/lib/test/DigestTests.cpp b/src/lib/test/DigestTests.cpp index db788ba3f..8c64e080f 100644 --- a/src/lib/test/DigestTests.cpp +++ b/src/lib/test/DigestTests.cpp @@ -315,7 +315,9 @@ void DigestTests::testDigestAll() CK_RV rv; CK_SESSION_HANDLE hSession; CK_MECHANISM mechanisms[] = { +#ifndef WITH_FIPS { CKM_MD5, NULL_PTR, 0 }, +#endif { CKM_SHA_1, NULL_PTR, 0 }, { CKM_SHA224, NULL_PTR, 0 }, { CKM_SHA256, NULL_PTR, 0 }, @@ -338,7 +340,7 @@ void DigestTests::testDigestAll() rv = C_OpenSession(SLOT_INIT_TOKEN, CKF_SERIAL_SESSION, NULL_PTR, NULL_PTR, &hSession); CPPUNIT_ASSERT(rv == CKR_OK); - for (int i = 0; i < 6; i++) + for (int i = 0; i < sizeof(mechanisms)/sizeof(CK_MECHANISM); i++) { rv = C_DigestInit(hSession, &mechanisms[i]); CPPUNIT_ASSERT(rv == CKR_OK); diff --git a/src/lib/test/SignVerifyTests.cpp b/src/lib/test/SignVerifyTests.cpp index e27a726d5..332819462 100644 --- a/src/lib/test/SignVerifyTests.cpp +++ b/src/lib/test/SignVerifyTests.cpp @@ -248,7 +248,9 @@ void SignVerifyTests::testRsaSignVerify() rsaPkcsSignVerify(CKM_RSA_PKCS, hSessionRO, hPuk,hPrk); rsaPkcsSignVerify(CKM_RSA_X_509, hSessionRO, hPuk,hPrk); +#ifndef WITH_FIPS digestRsaPkcsSignVerify(CKM_MD5_RSA_PKCS, hSessionRO, hPuk,hPrk); +#endif digestRsaPkcsSignVerify(CKM_SHA1_RSA_PKCS, hSessionRO, hPuk,hPrk); digestRsaPkcsSignVerify(CKM_SHA224_RSA_PKCS, hSessionRO, hPuk,hPrk); digestRsaPkcsSignVerify(CKM_SHA256_RSA_PKCS, hSessionRO, hPuk,hPrk); @@ -266,7 +268,9 @@ void SignVerifyTests::testRsaSignVerify() rsaPkcsSignVerify(CKM_RSA_PKCS, hSessionRW, hPuk,hPrk); rsaPkcsSignVerify(CKM_RSA_X_509, hSessionRW, hPuk,hPrk); +#ifndef WITH_FIPS digestRsaPkcsSignVerify(CKM_MD5_RSA_PKCS, hSessionRW, hPuk,hPrk); +#endif digestRsaPkcsSignVerify(CKM_SHA1_RSA_PKCS, hSessionRW, hPuk,hPrk); digestRsaPkcsSignVerify(CKM_SHA224_RSA_PKCS, hSessionRW, hPuk,hPrk); digestRsaPkcsSignVerify(CKM_SHA256_RSA_PKCS, hSessionRW, hPuk,hPrk); @@ -284,7 +288,9 @@ void SignVerifyTests::testRsaSignVerify() rsaPkcsSignVerify(CKM_RSA_PKCS, hSessionRW, hPuk,hPrk); rsaPkcsSignVerify(CKM_RSA_X_509, hSessionRW, hPuk,hPrk); +#ifndef WITH_FIPS digestRsaPkcsSignVerify(CKM_MD5_RSA_PKCS, hSessionRW, hPuk,hPrk); +#endif digestRsaPkcsSignVerify(CKM_SHA1_RSA_PKCS, hSessionRW, hPuk,hPrk); digestRsaPkcsSignVerify(CKM_SHA224_RSA_PKCS, hSessionRW, hPuk,hPrk); digestRsaPkcsSignVerify(CKM_SHA256_RSA_PKCS, hSessionRW, hPuk,hPrk); @@ -302,7 +308,9 @@ void SignVerifyTests::testRsaSignVerify() rsaPkcsSignVerify(CKM_RSA_PKCS, hSessionRW, hPuk,hPrk); rsaPkcsSignVerify(CKM_RSA_X_509, hSessionRW, hPuk,hPrk); +#ifndef WITH_FIPS digestRsaPkcsSignVerify(CKM_MD5_RSA_PKCS, hSessionRW, hPuk,hPrk); +#endif digestRsaPkcsSignVerify(CKM_SHA1_RSA_PKCS, hSessionRW, hPuk,hPrk); digestRsaPkcsSignVerify(CKM_SHA224_RSA_PKCS, hSessionRW, hPuk,hPrk); digestRsaPkcsSignVerify(CKM_SHA256_RSA_PKCS, hSessionRW, hPuk,hPrk); @@ -426,9 +434,11 @@ void SignVerifyTests::testHmacSignVerify() // Public Session keys CK_OBJECT_HANDLE hKey = CK_INVALID_HANDLE; +#ifndef WITH_FIPS rv = generateKey(hSessionRW,CKK_MD5_HMAC,IN_SESSION,IS_PUBLIC,hKey); CPPUNIT_ASSERT(rv == CKR_OK); hmacSignVerify(CKM_MD5_HMAC, hSessionRO, hKey); +#endif rv = generateKey(hSessionRW,CKK_SHA_1_HMAC,IN_SESSION,IS_PUBLIC,hKey); CPPUNIT_ASSERT(rv == CKR_OK); @@ -457,9 +467,11 @@ void SignVerifyTests::testHmacSignVerify() #endif // Private Session Keys +#ifndef WITH_FIPS rv = generateKey(hSessionRW,CKK_MD5_HMAC,IN_SESSION,IS_PRIVATE,hKey); CPPUNIT_ASSERT(rv == CKR_OK); hmacSignVerify(CKM_MD5_HMAC, hSessionRW, hKey); +#endif rv = generateKey(hSessionRW,CKK_SHA_1_HMAC,IN_SESSION,IS_PRIVATE,hKey); CPPUNIT_ASSERT(rv == CKR_OK); @@ -488,9 +500,11 @@ void SignVerifyTests::testHmacSignVerify() #endif // Public Token Keys +#ifndef WITH_FIPS rv = generateKey(hSessionRW,CKK_MD5_HMAC,ON_TOKEN,IS_PUBLIC,hKey); CPPUNIT_ASSERT(rv == CKR_OK); hmacSignVerify(CKM_MD5_HMAC, hSessionRW, hKey); +#endif rv = generateKey(hSessionRW,CKK_SHA_1_HMAC,ON_TOKEN,IS_PUBLIC,hKey); CPPUNIT_ASSERT(rv == CKR_OK); @@ -519,9 +533,11 @@ void SignVerifyTests::testHmacSignVerify() #endif // Private Token Keys +#ifndef WITH_FIPS rv = generateKey(hSessionRW,CKK_MD5_HMAC,ON_TOKEN,IS_PRIVATE,hKey); CPPUNIT_ASSERT(rv == CKR_OK); hmacSignVerify(CKM_MD5_HMAC, hSessionRW, hKey); +#endif rv = generateKey(hSessionRW,CKK_SHA_1_HMAC,ON_TOKEN,IS_PRIVATE,hKey); CPPUNIT_ASSERT(rv == CKR_OK); diff --git a/src/lib/test/SymmetricAlgorithmTests.cpp b/src/lib/test/SymmetricAlgorithmTests.cpp index c536c6fb4..5fa47d105 100644 --- a/src/lib/test/SymmetricAlgorithmTests.cpp +++ b/src/lib/test/SymmetricAlgorithmTests.cpp @@ -111,6 +111,7 @@ CK_RV SymmetricAlgorithmTests::generateAesKey(CK_SESSION_HANDLE hSession, CK_BBO &hKey); } +#ifndef WITH_FIPS CK_RV SymmetricAlgorithmTests::generateDesKey(CK_SESSION_HANDLE hSession, CK_BBOOL bToken, CK_BBOOL bPrivate, CK_OBJECT_HANDLE &hKey) { CK_MECHANISM mechanism = { CKM_DES_KEY_GEN, NULL_PTR, 0 }; @@ -146,6 +147,7 @@ CK_RV SymmetricAlgorithmTests::generateDes2Key(CK_SESSION_HANDLE hSession, CK_BB keyAttribs, sizeof(keyAttribs)/sizeof(CK_ATTRIBUTE), &hKey); } +#endif CK_RV SymmetricAlgorithmTests::generateDes3Key(CK_SESSION_HANDLE hSession, CK_BBOOL bToken, CK_BBOOL bPrivate, CK_OBJECT_HANDLE &hKey) { @@ -231,6 +233,7 @@ void SymmetricAlgorithmTests::aesEncryptDecrypt(CK_MECHANISM_TYPE mechanismType, CPPUNIT_ASSERT(memcmp(plainText, recoveredText, sizeof(plainText)) == 0); } +#ifndef WITH_FIPS void SymmetricAlgorithmTests::desEncryptDecrypt(CK_MECHANISM_TYPE mechanismType, CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hKey) { CK_MECHANISM mechanism = { mechanismType, NULL_PTR, 0 }; @@ -296,6 +299,7 @@ void SymmetricAlgorithmTests::desEncryptDecrypt(CK_MECHANISM_TYPE mechanismType, CPPUNIT_ASSERT(memcmp(plainText, recoveredText, sizeof(plainText)) == 0); } +#endif void SymmetricAlgorithmTests::des3EncryptDecrypt(CK_MECHANISM_TYPE mechanismType, CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hKey) { @@ -690,6 +694,7 @@ void SymmetricAlgorithmTests::testDesEncryptDecrypt() rv = C_Login(hSessionRO,CKU_USER,pin,pinLength); CPPUNIT_ASSERT(rv==CKR_OK); +#ifndef WITH_FIPS CK_OBJECT_HANDLE hKey = CK_INVALID_HANDLE; // Generate all combinations of session/token keys. @@ -707,6 +712,7 @@ void SymmetricAlgorithmTests::testDesEncryptDecrypt() des3EncryptDecrypt(CKM_DES3_ECB,hSessionRO,hKey2); des3EncryptDecrypt(CKM_DES3_CBC,hSessionRO,hKey2); +#endif CK_OBJECT_HANDLE hKey3 = CK_INVALID_HANDLE; @@ -724,7 +730,7 @@ void SymmetricAlgorithmTests::testNullTemplate() CK_UTF8CHAR pin[] = SLOT_0_USER1_PIN; CK_ULONG pinLength = sizeof(pin) - 1; CK_SESSION_HANDLE hSession; - CK_MECHANISM mechanism1 = { CKM_DES_KEY_GEN, NULL_PTR, 0 }; + CK_MECHANISM mechanism1 = { CKM_DES3_KEY_GEN, NULL_PTR, 0 }; CK_MECHANISM mechanism2 = { CKM_AES_KEY_GEN, NULL_PTR, 0 }; CK_OBJECT_HANDLE hKey = CK_INVALID_HANDLE; diff --git a/src/lib/test/SymmetricAlgorithmTests.h b/src/lib/test/SymmetricAlgorithmTests.h index 65cdc7c18..4d7ed33a7 100644 --- a/src/lib/test/SymmetricAlgorithmTests.h +++ b/src/lib/test/SymmetricAlgorithmTests.h @@ -58,11 +58,15 @@ class SymmetricAlgorithmTests : public CppUnit::TestFixture protected: CK_RV generateAesKey(CK_SESSION_HANDLE hSession, CK_BBOOL bToken, CK_BBOOL bPrivate, CK_OBJECT_HANDLE &hKey); +#ifndef WITH_FIPS CK_RV generateDesKey(CK_SESSION_HANDLE hSession, CK_BBOOL bToken, CK_BBOOL bPrivate, CK_OBJECT_HANDLE &hKey); CK_RV generateDes2Key(CK_SESSION_HANDLE hSession, CK_BBOOL bToken, CK_BBOOL bPrivate, CK_OBJECT_HANDLE &hKey); +#endif CK_RV generateDes3Key(CK_SESSION_HANDLE hSession, CK_BBOOL bToken, CK_BBOOL bPrivate, CK_OBJECT_HANDLE &hKey); void aesEncryptDecrypt(CK_MECHANISM_TYPE mechanismType, CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hKey); +#ifndef WITH_FIPS void desEncryptDecrypt(CK_MECHANISM_TYPE mechanismType, CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hKey); +#endif void des3EncryptDecrypt(CK_MECHANISM_TYPE mechanismType, CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hKey); void aesWrapUnwrap(CK_MECHANISM_TYPE mechanismType, CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hKey); #ifdef HAVE_AES_KEY_WRAP_PAD