You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by sc...@apache.org on 2016/12/16 21:18:40 UTC
svn commit: r1774662 [1/3] - in /santuario/xml-security-cpp/trunk/xsec:
enc/OpenSSL/ tools/checksig/
Author: scantor
Date: Fri Dec 16 21:18:39 2016
New Revision: 1774662
URL: http://svn.apache.org/viewvc?rev=1774662&view=rev
Log:
OpenSSL 1.1 compatibility - Tabs to spaces
Modified:
santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoBase64.hpp
santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHash.cpp
santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHash.hpp
santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHashHMAC.cpp
santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHashHMAC.hpp
santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.cpp
santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.hpp
santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyEC.cpp
santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyRSA.cpp
santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoProvider.cpp
santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoSymmetricKey.hpp
santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoX509.cpp
santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoX509.hpp
santuario/xml-security-cpp/trunk/xsec/tools/checksig/InteropResolver.cpp
santuario/xml-security-cpp/trunk/xsec/tools/checksig/InteropResolver.hpp
Modified: santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoBase64.hpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoBase64.hpp?rev=1774662&r1=1774661&r2=1774662&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoBase64.hpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoBase64.hpp Fri Dec 16 21:18:39 2016
@@ -36,7 +36,7 @@
// OpenSSL
#if defined (XSEC_HAVE_OPENSSL)
-# include <openssl/evp.h>
+# include <openssl/evp.h>
/**
* @ingroup opensslcrypto
@@ -65,144 +65,144 @@ class DSIG_EXPORT OpenSSLCryptoBase64 :
public :
-
- OpenSSLCryptoBase64() {};
- virtual ~OpenSSLCryptoBase64() {};
-
- /** @name Decoding Functions */
- //@{
-
- /**
- * \brief Initialise the base64 object.
- *
- * Initialises the OpenSSL decode context and gets ready for data
- * to be decoded.
- *
- */
-
- virtual void decodeInit(void);
-
- /**
- * \brief Decode some passed in data.
- *
- * Pass the encoded data through the OpenSSL base64 decode function
- * and place the data in the outData buffer.
- *
- * @note The OpenSSL library is very unkind if the output buffer is
- * not large enough. It is the responsibility of the caller to ensure
- * the buffer will take the data.
- *
- * @param inData Pointer to the buffer holding encoded data.
- * @param inLength Length of the encoded data in the buffer
- * @param outData Buffer to place decoded data into
- * @param outLength Maximum amount of data that can be placed in
- * the buffer.
- * @returns The number of bytes placed in the outData buffer.
- */
-
- virtual unsigned int decode(const unsigned char * inData,
- unsigned int inLength,
- unsigned char * outData,
- unsigned int outLength);
-
-
- /**
- * \brief Finish off a decode.
- *
- * Clean out any extra data in the OpenSSL decode context
- * variable into the outData buffer.
- *
- * @param outData Buffer to place any remaining decoded data
- * @param outLength Max amount of data to be placed in the buffer.
- * @returns Amount of data placed in the outData buffer
- */
-
- virtual unsigned int decodeFinish(unsigned char * outData,
- unsigned int outLength);
-
- //@}
-
- /** @name Encoding Functions */
- //@{
-
- /**
- * \brief Initialise the base64 object for encoding
- *
- * Get the context variable ready for a base64 decode
- *
- */
-
- virtual void encodeInit(void);
-
- /**
- * \brief Encode some passed in data.
- *
- * Pass the data through the OpenSSL Base64 encoder and place
- * the output in the outData buffer. Will keep any "overhang"
- * data in the context buffer ready for the next pass of input
- * data.
- *
- * @param inData Pointer to the buffer holding data to be encoded.
- * @param inLength Length of the data in the buffer
- * @param outData Buffer to place encoded data into
- * @param outLength Maximum amount of data that can be placed in
- * the buffer.
- * @returns The number of bytes placed in the outData buffer.
- */
-
- virtual unsigned int encode(const unsigned char * inData,
- unsigned int inLength,
- unsigned char * outData,
- unsigned int outLength);
-
- /**
- * \brief Finish off an encode.
- *
- * Take any data left in the context variable, and create the
- * tail of the base64 encoding.
- *
- * @param outData Buffer to place any remaining encoded data
- * @param outLength Max amount of data to be placed in the buffer.
- * @returns Amount of data placed in the outData buffer
- */
-
- virtual unsigned int encodeFinish(unsigned char * outData,
- unsigned int outLength); // Finish
-
-
- //@}
-
- /** @name Library Specific Functions */
- //@{
-
- /**
- * \brief Translate a base64 encoded BN to a bignum
- *
- * Take a ds:CryptoBinary number and translate to an OpenSSL
- * representation of a "big number" BIGNUM.
- *
- */
-
- static BIGNUM * b642BN(char * b64in, unsigned int len);
-
- /**
- * \brief Get OpenSSL encode context structure
- */
-
- EVP_ENCODE_CTX * getOpenSSLEncodeEVP_ENCODE_CTX(void) {return &m_ectx;}
-
- /**
- * \brief Get OpenSSL encode context structure
- */
+
+ OpenSSLCryptoBase64() {};
+ virtual ~OpenSSLCryptoBase64() {};
+
+ /** @name Decoding Functions */
+ //@{
+
+ /**
+ * \brief Initialise the base64 object.
+ *
+ * Initialises the OpenSSL decode context and gets ready for data
+ * to be decoded.
+ *
+ */
+
+ virtual void decodeInit(void);
+
+ /**
+ * \brief Decode some passed in data.
+ *
+ * Pass the encoded data through the OpenSSL base64 decode function
+ * and place the data in the outData buffer.
+ *
+ * @note The OpenSSL library is very unkind if the output buffer is
+ * not large enough. It is the responsibility of the caller to ensure
+ * the buffer will take the data.
+ *
+ * @param inData Pointer to the buffer holding encoded data.
+ * @param inLength Length of the encoded data in the buffer
+ * @param outData Buffer to place decoded data into
+ * @param outLength Maximum amount of data that can be placed in
+ * the buffer.
+ * @returns The number of bytes placed in the outData buffer.
+ */
+
+ virtual unsigned int decode(const unsigned char * inData,
+ unsigned int inLength,
+ unsigned char * outData,
+ unsigned int outLength);
+
+
+ /**
+ * \brief Finish off a decode.
+ *
+ * Clean out any extra data in the OpenSSL decode context
+ * variable into the outData buffer.
+ *
+ * @param outData Buffer to place any remaining decoded data
+ * @param outLength Max amount of data to be placed in the buffer.
+ * @returns Amount of data placed in the outData buffer
+ */
+
+ virtual unsigned int decodeFinish(unsigned char * outData,
+ unsigned int outLength);
+
+ //@}
+
+ /** @name Encoding Functions */
+ //@{
+
+ /**
+ * \brief Initialise the base64 object for encoding
+ *
+ * Get the context variable ready for a base64 decode
+ *
+ */
+
+ virtual void encodeInit(void);
+
+ /**
+ * \brief Encode some passed in data.
+ *
+ * Pass the data through the OpenSSL Base64 encoder and place
+ * the output in the outData buffer. Will keep any "overhang"
+ * data in the context buffer ready for the next pass of input
+ * data.
+ *
+ * @param inData Pointer to the buffer holding data to be encoded.
+ * @param inLength Length of the data in the buffer
+ * @param outData Buffer to place encoded data into
+ * @param outLength Maximum amount of data that can be placed in
+ * the buffer.
+ * @returns The number of bytes placed in the outData buffer.
+ */
+
+ virtual unsigned int encode(const unsigned char * inData,
+ unsigned int inLength,
+ unsigned char * outData,
+ unsigned int outLength);
+
+ /**
+ * \brief Finish off an encode.
+ *
+ * Take any data left in the context variable, and create the
+ * tail of the base64 encoding.
+ *
+ * @param outData Buffer to place any remaining encoded data
+ * @param outLength Max amount of data to be placed in the buffer.
+ * @returns Amount of data placed in the outData buffer
+ */
+
+ virtual unsigned int encodeFinish(unsigned char * outData,
+ unsigned int outLength); // Finish
+
+
+ //@}
+
+ /** @name Library Specific Functions */
+ //@{
+
+ /**
+ * \brief Translate a base64 encoded BN to a bignum
+ *
+ * Take a ds:CryptoBinary number and translate to an OpenSSL
+ * representation of a "big number" BIGNUM.
+ *
+ */
+
+ static BIGNUM * b642BN(char * b64in, unsigned int len);
+
+ /**
+ * \brief Get OpenSSL encode context structure
+ */
+
+ EVP_ENCODE_CTX * getOpenSSLEncodeEVP_ENCODE_CTX(void) {return &m_ectx;}
+
+ /**
+ * \brief Get OpenSSL encode context structure
+ */
- EVP_ENCODE_CTX * getOpenSSLDecodeEVP_ENCODE_CTX(void) {return &m_dctx;}
+ EVP_ENCODE_CTX * getOpenSSLDecodeEVP_ENCODE_CTX(void) {return &m_dctx;}
- //@}
+ //@}
private :
- EVP_ENCODE_CTX m_ectx; // Encode context
- EVP_ENCODE_CTX m_dctx; // Decode context
+ EVP_ENCODE_CTX m_ectx; // Encode context
+ EVP_ENCODE_CTX m_dctx; // Decode context
};
Modified: santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHash.cpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHash.cpp?rev=1774662&r1=1774661&r2=1774662&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHash.cpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHash.cpp Fri Dec 16 21:18:39 2016
@@ -40,79 +40,79 @@
OpenSSLCryptoHash::OpenSSLCryptoHash(HashType alg) {
- switch (alg) {
+ switch (alg) {
- case (XSECCryptoHash::HASH_SHA1) :
-
- mp_md = EVP_get_digestbyname("SHA1");
- break;
-
- case (XSECCryptoHash::HASH_MD5) :
-
- mp_md = EVP_get_digestbyname("MD5");
- break;
-
- case (XSECCryptoHash::HASH_SHA224) :
-
- mp_md = EVP_get_digestbyname("SHA224");
- if (mp_md == NULL) {
- throw XSECCryptoException(XSECCryptoException::MDError,
- "OpenSSL:Hash - SHA224 not supported by this version of OpenSSL");
- }
-
- break;
-
- case (XSECCryptoHash::HASH_SHA256) :
-
- mp_md = EVP_get_digestbyname("SHA256");
- if (mp_md == NULL) {
- throw XSECCryptoException(XSECCryptoException::MDError,
- "OpenSSL:Hash - SHA256 not supported by this version of OpenSSL");
- }
-
- break;
-
- case (XSECCryptoHash::HASH_SHA384) :
-
- mp_md = EVP_get_digestbyname("SHA384");
- if (mp_md == NULL) {
- throw XSECCryptoException(XSECCryptoException::MDError,
- "OpenSSL:Hash - SHA384 not supported by this version of OpenSSL");
- }
-
- break;
-
- case (XSECCryptoHash::HASH_SHA512) :
-
- mp_md = EVP_get_digestbyname("SHA512");
- if (mp_md == NULL) {
- throw XSECCryptoException(XSECCryptoException::MDError,
- "OpenSSL:Hash - SHA512 not supported by this version of OpenSSL");
- }
-
- break;
-
- default :
-
- mp_md = NULL;
-
- }
-
- if(!mp_md) {
-
- throw XSECCryptoException(XSECCryptoException::MDError,
- "OpenSSL:Hash - Error loading Message Digest");
- }
+ case (XSECCryptoHash::HASH_SHA1) :
+
+ mp_md = EVP_get_digestbyname("SHA1");
+ break;
+
+ case (XSECCryptoHash::HASH_MD5) :
+
+ mp_md = EVP_get_digestbyname("MD5");
+ break;
+
+ case (XSECCryptoHash::HASH_SHA224) :
+
+ mp_md = EVP_get_digestbyname("SHA224");
+ if (mp_md == NULL) {
+ throw XSECCryptoException(XSECCryptoException::MDError,
+ "OpenSSL:Hash - SHA224 not supported by this version of OpenSSL");
+ }
+
+ break;
+
+ case (XSECCryptoHash::HASH_SHA256) :
+
+ mp_md = EVP_get_digestbyname("SHA256");
+ if (mp_md == NULL) {
+ throw XSECCryptoException(XSECCryptoException::MDError,
+ "OpenSSL:Hash - SHA256 not supported by this version of OpenSSL");
+ }
+
+ break;
+
+ case (XSECCryptoHash::HASH_SHA384) :
+
+ mp_md = EVP_get_digestbyname("SHA384");
+ if (mp_md == NULL) {
+ throw XSECCryptoException(XSECCryptoException::MDError,
+ "OpenSSL:Hash - SHA384 not supported by this version of OpenSSL");
+ }
+
+ break;
+
+ case (XSECCryptoHash::HASH_SHA512) :
+
+ mp_md = EVP_get_digestbyname("SHA512");
+ if (mp_md == NULL) {
+ throw XSECCryptoException(XSECCryptoException::MDError,
+ "OpenSSL:Hash - SHA512 not supported by this version of OpenSSL");
+ }
+
+ break;
+
+ default :
+
+ mp_md = NULL;
+
+ }
+
+ if(!mp_md) {
+
+ throw XSECCryptoException(XSECCryptoException::MDError,
+ "OpenSSL:Hash - Error loading Message Digest");
+ }
- EVP_DigestInit(&m_mdctx, mp_md);
- m_hashType = alg;
+ EVP_DigestInit(&m_mdctx, mp_md);
+ m_hashType = alg;
}
OpenSSLCryptoHash::~OpenSSLCryptoHash() {
- EVP_MD_CTX_cleanup(&m_mdctx);
+ EVP_MD_CTX_cleanup(&m_mdctx);
}
@@ -121,33 +121,33 @@ OpenSSLCryptoHash::~OpenSSLCryptoHash()
// Hashing Activities
void OpenSSLCryptoHash::reset(void) {
- EVP_MD_CTX_cleanup(&m_mdctx);
+ EVP_MD_CTX_cleanup(&m_mdctx);
- EVP_DigestInit(&m_mdctx, mp_md);
+ EVP_DigestInit(&m_mdctx, mp_md);
}
void OpenSSLCryptoHash::hash(unsigned char * data,
- unsigned int length) {
+ unsigned int length) {
- EVP_DigestUpdate(&m_mdctx, data, length);
+ EVP_DigestUpdate(&m_mdctx, data, length);
}
unsigned int OpenSSLCryptoHash::finish(unsigned char * hash,
- unsigned int maxLength) {
+ unsigned int maxLength) {
- unsigned int retLen;
+ unsigned int retLen;
- // Finish up and copy out hash, returning the length
+ // Finish up and copy out hash, returning the length
- EVP_DigestFinal(&m_mdctx, m_mdValue, &m_mdLen);
+ EVP_DigestFinal(&m_mdctx, m_mdValue, &m_mdLen);
- // Copy to output buffer
-
- retLen = (maxLength > m_mdLen ? m_mdLen : maxLength);
- memcpy(hash, m_mdValue, retLen);
+ // Copy to output buffer
+
+ retLen = (maxLength > m_mdLen ? m_mdLen : maxLength);
+ memcpy(hash, m_mdValue, retLen);
- return retLen;
+ return retLen;
}
@@ -155,7 +155,7 @@ unsigned int OpenSSLCryptoHash::finish(u
XSECCryptoHash::HashType OpenSSLCryptoHash::getHashType(void) const {
- return m_hashType; // This could be any kind of hash
+ return m_hashType; // This could be any kind of hash
}
Modified: santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHash.hpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHash.hpp?rev=1774662&r1=1774661&r2=1774662&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHash.hpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHash.hpp Fri Dec 16 21:18:39 2016
@@ -38,7 +38,7 @@
#if defined (XSEC_HAVE_OPENSSL)
-# include <openssl/evp.h>
+# include <openssl/evp.h>
/**
* @ingroup opensslcrypto
@@ -56,103 +56,103 @@ class DSIG_EXPORT OpenSSLCryptoHash : pu
public :
- /** @name Constructors and Destructors */
- //@{
+ /** @name Constructors and Destructors */
+ //@{
- OpenSSLCryptoHash(XSECCryptoHash::HashType alg);
- virtual ~OpenSSLCryptoHash();
-
- //@}
-
- /** @name HMAC Functions */
- //@{
-
- /**
- *\brief
- *
- * Does nothing. If the required function is an HMAC function,
- * then OpenSSLCryptoHashHMAC should be used.
- *
- * @param key The key the HMAC function should use.
- */
-
- virtual void setKey(XSECCryptoKey * key) {}
-
- //@}
-
- /** @name Digest/Hash functions */
- //@{
-
- /**
- * \brief Rest the hash function
- *
- * Re-initialises the digest structure.
- */
-
- virtual void reset(void);
-
- /**
- * \brief Hash some data.
- *
- * Take length bytes of data from the data buffer and update the hash
- * that already exists. This function may (and normally will) be called
- * many times for large blocks of data.
- *
- * @param data The buffer containing the data to be hashed.
- * @param length The number of bytes to be read from data
- */
-
- virtual void hash(unsigned char * data,
- unsigned int length);
- /**
- * \brief Finish up a Digest operation and read the result.
- *
- * This call tells the CryptoHash object that the input is complete and
- * to finalise the Digest. The output of the digest is read into the
- * hash buffer (at most maxLength bytes)
- *
- * @param hash The buffer the hash should be read into.
- * @param maxLength The maximum number of bytes to be read into hash
- * @returns The number of bytes copied into the hash buffer
- */
-
- virtual unsigned int finish(unsigned char * hash,
- unsigned int maxLength);// Finish and get hash
-
- //@}
-
- /** @name Information functions */
- //@{
-
- /**
- *\brief
- *
- * Determine the hash type of this object
- *
- * @returns The hash type
- */
-
- virtual HashType getHashType(void) const;
-
- /**
- * \brief Get OpenSSL hash context structure
- */
+ OpenSSLCryptoHash(XSECCryptoHash::HashType alg);
+ virtual ~OpenSSLCryptoHash();
+
+ //@}
+
+ /** @name HMAC Functions */
+ //@{
+
+ /**
+ *\brief
+ *
+ * Does nothing. If the required function is an HMAC function,
+ * then OpenSSLCryptoHashHMAC should be used.
+ *
+ * @param key The key the HMAC function should use.
+ */
+
+ virtual void setKey(XSECCryptoKey * key) {}
+
+ //@}
+
+ /** @name Digest/Hash functions */
+ //@{
+
+ /**
+ * \brief Rest the hash function
+ *
+ * Re-initialises the digest structure.
+ */
+
+ virtual void reset(void);
+
+ /**
+ * \brief Hash some data.
+ *
+ * Take length bytes of data from the data buffer and update the hash
+ * that already exists. This function may (and normally will) be called
+ * many times for large blocks of data.
+ *
+ * @param data The buffer containing the data to be hashed.
+ * @param length The number of bytes to be read from data
+ */
+
+ virtual void hash(unsigned char * data,
+ unsigned int length);
+ /**
+ * \brief Finish up a Digest operation and read the result.
+ *
+ * This call tells the CryptoHash object that the input is complete and
+ * to finalise the Digest. The output of the digest is read into the
+ * hash buffer (at most maxLength bytes)
+ *
+ * @param hash The buffer the hash should be read into.
+ * @param maxLength The maximum number of bytes to be read into hash
+ * @returns The number of bytes copied into the hash buffer
+ */
+
+ virtual unsigned int finish(unsigned char * hash,
+ unsigned int maxLength);// Finish and get hash
+
+ //@}
+
+ /** @name Information functions */
+ //@{
+
+ /**
+ *\brief
+ *
+ * Determine the hash type of this object
+ *
+ * @returns The hash type
+ */
+
+ virtual HashType getHashType(void) const;
+
+ /**
+ * \brief Get OpenSSL hash context structure
+ */
- EVP_MD_CTX * getOpenSSLEVP_MD_CTX(void) {return &m_mdctx;}
+ EVP_MD_CTX * getOpenSSLEVP_MD_CTX(void) {return &m_mdctx;}
- //@}
+ //@}
private:
- // Not implemented constructors
- OpenSSLCryptoHash();
+ // Not implemented constructors
+ OpenSSLCryptoHash();
- EVP_MD_CTX m_mdctx; // Context for digest
- const EVP_MD * mp_md; // Digest instance
- unsigned char m_mdValue[EVP_MAX_MD_SIZE]; // Final output
- unsigned int m_mdLen; // Length of digest
- HashType m_hashType; // What type of hash is this?
+ EVP_MD_CTX m_mdctx; // Context for digest
+ const EVP_MD * mp_md; // Digest instance
+ unsigned char m_mdValue[EVP_MAX_MD_SIZE]; // Final output
+ unsigned int m_mdLen; // Length of digest
+ HashType m_hashType; // What type of hash is this?
};
Modified: santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHashHMAC.cpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHashHMAC.cpp?rev=1774662&r1=1774661&r2=1774662&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHashHMAC.cpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHashHMAC.cpp Fri Dec 16 21:18:39 2016
@@ -42,104 +42,104 @@
OpenSSLCryptoHashHMAC::OpenSSLCryptoHashHMAC(HashType alg) {
- // Initialise the digest
+ // Initialise the digest
- switch (alg) {
+ switch (alg) {
- case (XSECCryptoHash::HASH_SHA1) :
-
- mp_md = EVP_get_digestbyname("SHA1");
- break;
-
- case (XSECCryptoHash::HASH_MD5) :
-
- mp_md = EVP_get_digestbyname("MD5");
- break;
-
- case (XSECCryptoHash::HASH_SHA224) :
-
- mp_md = EVP_get_digestbyname("SHA224");
- if (mp_md == NULL) {
- throw XSECCryptoException(XSECCryptoException::MDError,
- "OpenSSL:Hash - SHA224 not supported by this version of OpenSSL");
- }
-
- break;
-
- case (XSECCryptoHash::HASH_SHA256) :
-
- mp_md = EVP_get_digestbyname("SHA256");
- if (mp_md == NULL) {
- throw XSECCryptoException(XSECCryptoException::MDError,
- "OpenSSL:Hash - SHA256 not supported by this version of OpenSSL");
- }
-
- break;
-
- case (XSECCryptoHash::HASH_SHA384) :
-
- mp_md = EVP_get_digestbyname("SHA384");
- if (mp_md == NULL) {
- throw XSECCryptoException(XSECCryptoException::MDError,
- "OpenSSL:Hash - SHA384 not supported by this version of OpenSSL");
- }
-
- break;
-
- case (XSECCryptoHash::HASH_SHA512) :
-
- mp_md = EVP_get_digestbyname("SHA512");
- if (mp_md == NULL) {
- throw XSECCryptoException(XSECCryptoException::MDError,
- "OpenSSL:Hash - SHA512 not supported by this version of OpenSSL");
- }
-
- break;
-
- default :
-
- mp_md = NULL;
-
- }
-
- if(!mp_md) {
-
- throw XSECCryptoException(XSECCryptoException::MDError,
- "OpenSSL:HashHMAC - Error loading Message Digest");
- }
+ case (XSECCryptoHash::HASH_SHA1) :
+
+ mp_md = EVP_get_digestbyname("SHA1");
+ break;
+
+ case (XSECCryptoHash::HASH_MD5) :
+
+ mp_md = EVP_get_digestbyname("MD5");
+ break;
+
+ case (XSECCryptoHash::HASH_SHA224) :
+
+ mp_md = EVP_get_digestbyname("SHA224");
+ if (mp_md == NULL) {
+ throw XSECCryptoException(XSECCryptoException::MDError,
+ "OpenSSL:Hash - SHA224 not supported by this version of OpenSSL");
+ }
+
+ break;
+
+ case (XSECCryptoHash::HASH_SHA256) :
+
+ mp_md = EVP_get_digestbyname("SHA256");
+ if (mp_md == NULL) {
+ throw XSECCryptoException(XSECCryptoException::MDError,
+ "OpenSSL:Hash - SHA256 not supported by this version of OpenSSL");
+ }
+
+ break;
+
+ case (XSECCryptoHash::HASH_SHA384) :
+
+ mp_md = EVP_get_digestbyname("SHA384");
+ if (mp_md == NULL) {
+ throw XSECCryptoException(XSECCryptoException::MDError,
+ "OpenSSL:Hash - SHA384 not supported by this version of OpenSSL");
+ }
+
+ break;
+
+ case (XSECCryptoHash::HASH_SHA512) :
+
+ mp_md = EVP_get_digestbyname("SHA512");
+ if (mp_md == NULL) {
+ throw XSECCryptoException(XSECCryptoException::MDError,
+ "OpenSSL:Hash - SHA512 not supported by this version of OpenSSL");
+ }
+
+ break;
+
+ default :
+
+ mp_md = NULL;
+
+ }
+
+ if(!mp_md) {
+
+ throw XSECCryptoException(XSECCryptoException::MDError,
+ "OpenSSL:HashHMAC - Error loading Message Digest");
+ }
- m_initialised = false;
- m_hashType = alg;
+ m_initialised = false;
+ m_hashType = alg;
}
void OpenSSLCryptoHashHMAC::setKey(XSECCryptoKey *key) {
- // Use this to initialise the HMAC Context
+ // Use this to initialise the HMAC Context
- if (key->getKeyType() != XSECCryptoKey::KEY_HMAC) {
+ if (key->getKeyType() != XSECCryptoKey::KEY_HMAC) {
- throw XSECCryptoException(XSECCryptoException::MDError,
- "OpenSSL:HashHMAC - Non HMAC Key passed to OpenSSLHashHMAC");
+ throw XSECCryptoException(XSECCryptoException::MDError,
+ "OpenSSL:HashHMAC - Non HMAC Key passed to OpenSSLHashHMAC");
- }
+ }
- m_keyLen = ((XSECCryptoKeyHMAC *) key)->getKey(m_keyBuf);
+ m_keyLen = ((XSECCryptoKeyHMAC *) key)->getKey(m_keyBuf);
- HMAC_Init(&m_hctx,
- m_keyBuf.rawBuffer(),
- m_keyLen,
- mp_md);
+ HMAC_Init(&m_hctx,
+ m_keyBuf.rawBuffer(),
+ m_keyLen,
+ mp_md);
- m_initialised = true;
+ m_initialised = true;
}
OpenSSLCryptoHashHMAC::~OpenSSLCryptoHashHMAC() {
- if (m_initialised)
- HMAC_CTX_cleanup(&m_hctx);
+ if (m_initialised)
+ HMAC_CTX_cleanup(&m_hctx);
}
@@ -149,46 +149,46 @@ OpenSSLCryptoHashHMAC::~OpenSSLCryptoHas
void OpenSSLCryptoHashHMAC::reset(void) {
- if (m_initialised) {
+ if (m_initialised) {
- HMAC_CTX_cleanup(&m_hctx);
+ HMAC_CTX_cleanup(&m_hctx);
- HMAC_Init(&m_hctx,
- m_keyBuf.rawBuffer(),
- m_keyLen,
- mp_md);
+ HMAC_Init(&m_hctx,
+ m_keyBuf.rawBuffer(),
+ m_keyLen,
+ mp_md);
- }
+ }
}
void OpenSSLCryptoHashHMAC::hash(unsigned char * data,
- unsigned int length) {
+ unsigned int length) {
- if (!m_initialised)
- throw XSECCryptoException(XSECCryptoException::MDError,
- "OpenSSL:HashHMAC - hash called prior to setKey");
+ if (!m_initialised)
+ throw XSECCryptoException(XSECCryptoException::MDError,
+ "OpenSSL:HashHMAC - hash called prior to setKey");
- HMAC_Update(&m_hctx, data, (int) length);
+ HMAC_Update(&m_hctx, data, (int) length);
}
unsigned int OpenSSLCryptoHashHMAC::finish(unsigned char * hash,
- unsigned int maxLength) {
+ unsigned int maxLength) {
- unsigned int retLen;
+ unsigned int retLen;
- // Finish up and copy out hash, returning the length
+ // Finish up and copy out hash, returning the length
- HMAC_Final(&m_hctx, m_mdValue, &m_mdLen);
+ HMAC_Final(&m_hctx, m_mdValue, &m_mdLen);
- // Copy to output buffer
-
- retLen = (maxLength > m_mdLen ? m_mdLen : maxLength);
- memcpy(hash, m_mdValue, retLen);
+ // Copy to output buffer
+
+ retLen = (maxLength > m_mdLen ? m_mdLen : maxLength);
+ memcpy(hash, m_mdValue, retLen);
- return retLen;
+ return retLen;
}
@@ -196,7 +196,7 @@ unsigned int OpenSSLCryptoHashHMAC::fini
XSECCryptoHash::HashType OpenSSLCryptoHashHMAC::getHashType(void) const {
- return m_hashType; // This could be any kind of hash
+ return m_hashType; // This could be any kind of hash
}
Modified: santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHashHMAC.hpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHashHMAC.hpp?rev=1774662&r1=1774661&r2=1774662&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHashHMAC.hpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoHashHMAC.hpp Fri Dec 16 21:18:39 2016
@@ -57,128 +57,128 @@ class DSIG_EXPORT OpenSSLCryptoHashHMAC
public :
- /** @name Constructors and Destructors */
- //@{
+ /** @name Constructors and Destructors */
+ //@{
- /**
- * \brief Constructor
- *
- * Create the object, with the indicated algorithm
- * (Currently supports MD5 and SHA1)
- *
- * @param alg Digest algorithm to use
- */
-
- OpenSSLCryptoHashHMAC(XSECCryptoHash::HashType alg);
-
- /**
- * \brief Destructor
- *
- * Destroy the object. Will ensure any key material is also destroyed
- */
-
- virtual ~OpenSSLCryptoHashHMAC();
-
- //@}
-
- /** @name HMAC Functions */
- //@{
-
- /**
- *\brief Set the HMAC key
- *
- * Sets the key - which needs to have a base class of
- * OpenSSLCryptoKeyHMAC.
- *
- * @param key The key the HMAC function should use.
- */
-
- virtual void setKey(XSECCryptoKey * key);
-
- /**
- * \brief Return the string identifier for the OpenSSL interface
- */
-
- virtual const XMLCh * getProviderName() {return DSIGConstants::s_unicodeStrPROVOpenSSL;}
-
- //@}
-
- /** @name Hash Functions */
- //{@
-
- /**
- * \brief Reset the hash function
- *
- * Re-initialises the digest structure.
- */
-
- virtual void reset(void);
-
- /**
- * \brief Hash some data.
- *
- * Take length bytes of data from the data buffer and update the hash
- * that already exists. This function may (and normally will) be called
- * many times for large blocks of data.
- *
- * @param data The buffer containing the data to be hashed.
- * @param length The number of bytes to be read from data
- */
-
- virtual void hash(unsigned char * data,
- unsigned int length);
- /**
- * \brief Finish up a Digest operation and read the result.
- *
- * This call tells the CryptoHash object that the input is complete and
- * to finalise the Digest. The output of the digest is read into the
- * hash buffer (at most maxLength bytes). This is effectively the
- * signature for the data that has been run through the HMAC function.
- *
- * @param hash The buffer the hash should be read into.
- * @param maxLength The maximum number of bytes to be read into hash
- * @returns The number of bytes copied into the hash buffer
- */
-
- virtual unsigned int finish(unsigned char * hash,
- unsigned int maxLength);// Finish and get hash
-
- //@}
-
- /** @name Information functions */
- //@{
-
- /**
- *\brief
- *
- * Determine the hash type of this object
- *
- * @returns The hash type
- */
-
- virtual HashType getHashType(void) const;
-
- /**
- * \brief Get OpenSSL Hash Context
- */
+ /**
+ * \brief Constructor
+ *
+ * Create the object, with the indicated algorithm
+ * (Currently supports MD5 and SHA1)
+ *
+ * @param alg Digest algorithm to use
+ */
+
+ OpenSSLCryptoHashHMAC(XSECCryptoHash::HashType alg);
+
+ /**
+ * \brief Destructor
+ *
+ * Destroy the object. Will ensure any key material is also destroyed
+ */
+
+ virtual ~OpenSSLCryptoHashHMAC();
+
+ //@}
+
+ /** @name HMAC Functions */
+ //@{
+
+ /**
+ *\brief Set the HMAC key
+ *
+ * Sets the key - which needs to have a base class of
+ * OpenSSLCryptoKeyHMAC.
+ *
+ * @param key The key the HMAC function should use.
+ */
+
+ virtual void setKey(XSECCryptoKey * key);
+
+ /**
+ * \brief Return the string identifier for the OpenSSL interface
+ */
+
+ virtual const XMLCh * getProviderName() {return DSIGConstants::s_unicodeStrPROVOpenSSL;}
+
+ //@}
+
+ /** @name Hash Functions */
+ //{@
+
+ /**
+ * \brief Reset the hash function
+ *
+ * Re-initialises the digest structure.
+ */
+
+ virtual void reset(void);
+
+ /**
+ * \brief Hash some data.
+ *
+ * Take length bytes of data from the data buffer and update the hash
+ * that already exists. This function may (and normally will) be called
+ * many times for large blocks of data.
+ *
+ * @param data The buffer containing the data to be hashed.
+ * @param length The number of bytes to be read from data
+ */
+
+ virtual void hash(unsigned char * data,
+ unsigned int length);
+ /**
+ * \brief Finish up a Digest operation and read the result.
+ *
+ * This call tells the CryptoHash object that the input is complete and
+ * to finalise the Digest. The output of the digest is read into the
+ * hash buffer (at most maxLength bytes). This is effectively the
+ * signature for the data that has been run through the HMAC function.
+ *
+ * @param hash The buffer the hash should be read into.
+ * @param maxLength The maximum number of bytes to be read into hash
+ * @returns The number of bytes copied into the hash buffer
+ */
+
+ virtual unsigned int finish(unsigned char * hash,
+ unsigned int maxLength);// Finish and get hash
+
+ //@}
+
+ /** @name Information functions */
+ //@{
+
+ /**
+ *\brief
+ *
+ * Determine the hash type of this object
+ *
+ * @returns The hash type
+ */
+
+ virtual HashType getHashType(void) const;
+
+ /**
+ * \brief Get OpenSSL Hash Context
+ */
- HMAC_CTX * getOpenSSLHMAC_CTX(void) {return &m_hctx;}
+ HMAC_CTX * getOpenSSLHMAC_CTX(void) {return &m_hctx;}
- //@}
+ //@}
private:
- // Not implemented constructors
- OpenSSLCryptoHashHMAC();
+ // Not implemented constructors
+ OpenSSLCryptoHashHMAC();
- const EVP_MD * mp_md; // Digest instance
- unsigned char m_mdValue[EVP_MAX_MD_SIZE]; // Final output
- unsigned int m_mdLen; // Length of digest
- HashType m_hashType; // What type of hash is this?
- HMAC_CTX m_hctx; // Context for HMAC
- safeBuffer m_keyBuf; // The loaded key
- unsigned int m_keyLen; // The loaded key length
- bool m_initialised;
+ const EVP_MD * mp_md; // Digest instance
+ unsigned char m_mdValue[EVP_MAX_MD_SIZE]; // Final output
+ unsigned int m_mdLen; // Length of digest
+ HashType m_hashType; // What type of hash is this?
+ HMAC_CTX m_hctx; // Context for HMAC
+ safeBuffer m_keyBuf; // The loaded key
+ unsigned int m_keyLen; // The loaded key length
+ bool m_initialised;
};
#endif /* XSEC_HAVE_OPENSSL */
Modified: santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.cpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.cpp?rev=1774662&r1=1774661&r2=1774662&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.cpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.cpp Fri Dec 16 21:18:39 2016
@@ -48,11 +48,11 @@ OpenSSLCryptoKeyDSA::OpenSSLCryptoKeyDSA
OpenSSLCryptoKeyDSA::~OpenSSLCryptoKeyDSA() {
- // If we have a DSA, delete it
- // OpenSSL will ensure the memory holding any private key is freed.
+ // If we have a DSA, delete it
+ // OpenSSL will ensure the memory holding any private key is freed.
- if (mp_dsaKey)
- DSA_free(mp_dsaKey);
+ if (mp_dsaKey)
+ DSA_free(mp_dsaKey);
};
@@ -60,65 +60,65 @@ OpenSSLCryptoKeyDSA::~OpenSSLCryptoKeyDS
XSECCryptoKey::KeyType OpenSSLCryptoKeyDSA::getKeyType() const {
- // Find out what we have
- if (mp_dsaKey == NULL)
- return KEY_NONE;
+ // Find out what we have
+ if (mp_dsaKey == NULL)
+ return KEY_NONE;
- if (mp_dsaKey->priv_key != NULL && mp_dsaKey->pub_key != NULL)
- return KEY_DSA_PAIR;
+ if (mp_dsaKey->priv_key != NULL && mp_dsaKey->pub_key != NULL)
+ return KEY_DSA_PAIR;
- if (mp_dsaKey->priv_key != NULL)
- return KEY_DSA_PRIVATE;
+ if (mp_dsaKey->priv_key != NULL)
+ return KEY_DSA_PRIVATE;
- if (mp_dsaKey->pub_key != NULL)
- return KEY_DSA_PUBLIC;
+ if (mp_dsaKey->pub_key != NULL)
+ return KEY_DSA_PUBLIC;
- return KEY_NONE;
+ return KEY_NONE;
}
void OpenSSLCryptoKeyDSA::loadPBase64BigNums(const char * b64, unsigned int len) {
- if (mp_dsaKey == NULL)
- mp_dsaKey = DSA_new();
+ if (mp_dsaKey == NULL)
+ mp_dsaKey = DSA_new();
- mp_dsaKey->p = OpenSSLCryptoBase64::b642BN((char *) b64, len);
+ mp_dsaKey->p = OpenSSLCryptoBase64::b642BN((char *) b64, len);
}
void OpenSSLCryptoKeyDSA::loadQBase64BigNums(const char * b64, unsigned int len) {
- if (mp_dsaKey == NULL)
- mp_dsaKey = DSA_new();
+ if (mp_dsaKey == NULL)
+ mp_dsaKey = DSA_new();
- mp_dsaKey->q = OpenSSLCryptoBase64::b642BN((char *) b64, len);
+ mp_dsaKey->q = OpenSSLCryptoBase64::b642BN((char *) b64, len);
}
void OpenSSLCryptoKeyDSA::loadGBase64BigNums(const char * b64, unsigned int len) {
- if (mp_dsaKey == NULL)
- mp_dsaKey = DSA_new();
+ if (mp_dsaKey == NULL)
+ mp_dsaKey = DSA_new();
- mp_dsaKey->g = OpenSSLCryptoBase64::b642BN((char *) b64, len);
+ mp_dsaKey->g = OpenSSLCryptoBase64::b642BN((char *) b64, len);
}
void OpenSSLCryptoKeyDSA::loadYBase64BigNums(const char * b64, unsigned int len) {
- if (mp_dsaKey == NULL)
- mp_dsaKey = DSA_new();
+ if (mp_dsaKey == NULL)
+ mp_dsaKey = DSA_new();
- mp_dsaKey->pub_key = OpenSSLCryptoBase64::b642BN((char *) b64, len);
+ mp_dsaKey->pub_key = OpenSSLCryptoBase64::b642BN((char *) b64, len);
}
void OpenSSLCryptoKeyDSA::loadJBase64BigNums(const char * b64, unsigned int len) {
- if (mp_dsaKey == NULL)
- mp_dsaKey = DSA_new();
+ if (mp_dsaKey == NULL)
+ mp_dsaKey = DSA_new();
- // Do nothing
+ // Do nothing
}
@@ -126,24 +126,24 @@ void OpenSSLCryptoKeyDSA::loadJBase64Big
OpenSSLCryptoKeyDSA::OpenSSLCryptoKeyDSA(EVP_PKEY *k) {
- // Create a new key to be loaded as we go
+ // Create a new key to be loaded as we go
- mp_dsaKey = DSA_new();
+ mp_dsaKey = DSA_new();
- if (k == NULL || k->type != EVP_PKEY_DSA)
- return; // Nothing to do with us
+ if (k == NULL || k->type != EVP_PKEY_DSA)
+ return; // Nothing to do with us
- if (k->pkey.dsa->p)
- mp_dsaKey->p = BN_dup(k->pkey.dsa->p);
- if (k->pkey.dsa->q)
- mp_dsaKey->q = BN_dup(k->pkey.dsa->q);
- if (k->pkey.dsa->g)
- mp_dsaKey->g = BN_dup(k->pkey.dsa->g);
- if (k->pkey.dsa->pub_key)
- mp_dsaKey->pub_key = BN_dup(k->pkey.dsa->pub_key);
- if (k->pkey.dsa->priv_key)
- mp_dsaKey->priv_key = BN_dup(k->pkey.dsa->priv_key);
+ if (k->pkey.dsa->p)
+ mp_dsaKey->p = BN_dup(k->pkey.dsa->p);
+ if (k->pkey.dsa->q)
+ mp_dsaKey->q = BN_dup(k->pkey.dsa->q);
+ if (k->pkey.dsa->g)
+ mp_dsaKey->g = BN_dup(k->pkey.dsa->g);
+ if (k->pkey.dsa->pub_key)
+ mp_dsaKey->pub_key = BN_dup(k->pkey.dsa->pub_key);
+ if (k->pkey.dsa->priv_key)
+ mp_dsaKey->priv_key = BN_dup(k->pkey.dsa->priv_key);
}
@@ -152,97 +152,97 @@ OpenSSLCryptoKeyDSA::OpenSSLCryptoKeyDSA
// --------------------------------------------------------------------------------
bool OpenSSLCryptoKeyDSA::verifyBase64Signature(unsigned char * hashBuf,
- unsigned int hashLen,
- char * base64Signature,
- unsigned int sigLen) {
+ unsigned int hashLen,
+ char * base64Signature,
+ unsigned int sigLen) {
- // Use the currently loaded key to validate the Base64 encoded signature
+ // Use the currently loaded key to validate the Base64 encoded signature
- if (mp_dsaKey == NULL) {
+ if (mp_dsaKey == NULL) {
- throw XSECCryptoException(XSECCryptoException::DSAError,
- "OpenSSL:DSA - Attempt to validate signature with empty key");
- }
+ throw XSECCryptoException(XSECCryptoException::DSAError,
+ "OpenSSL:DSA - Attempt to validate signature with empty key");
+ }
char* cleanedBase64Signature;
- unsigned int cleanedBase64SignatureLen = 0;
+ unsigned int cleanedBase64SignatureLen = 0;
- cleanedBase64Signature =
- XSECCryptoBase64::cleanBuffer(base64Signature, sigLen, cleanedBase64SignatureLen);
- ArrayJanitor<char> j_cleanedBase64Signature(cleanedBase64Signature);
+ cleanedBase64Signature =
+ XSECCryptoBase64::cleanBuffer(base64Signature, sigLen, cleanedBase64SignatureLen);
+ ArrayJanitor<char> j_cleanedBase64Signature(cleanedBase64Signature);
- int sigValLen;
- unsigned char* sigVal = new unsigned char[sigLen + 1];
+ int sigValLen;
+ unsigned char* sigVal = new unsigned char[sigLen + 1];
ArrayJanitor<unsigned char> j_sigVal(sigVal);
- EVP_ENCODE_CTX m_dctx;
- EVP_DecodeInit(&m_dctx);
- int rc = EVP_DecodeUpdate(&m_dctx,
- sigVal,
- &sigValLen,
- (unsigned char *) cleanedBase64Signature,
- cleanedBase64SignatureLen);
+ EVP_ENCODE_CTX m_dctx;
+ EVP_DecodeInit(&m_dctx);
+ int rc = EVP_DecodeUpdate(&m_dctx,
+ sigVal,
+ &sigValLen,
+ (unsigned char *) cleanedBase64Signature,
+ cleanedBase64SignatureLen);
- if (rc < 0) {
+ if (rc < 0) {
- throw XSECCryptoException(XSECCryptoException::DSAError,
- "OpenSSL:DSA - Error during Base64 Decode");
- }
- int t = 0;
+ throw XSECCryptoException(XSECCryptoException::DSAError,
+ "OpenSSL:DSA - Error during Base64 Decode");
+ }
+ int t = 0;
- EVP_DecodeFinal(&m_dctx, &sigVal[sigValLen], &t);
+ EVP_DecodeFinal(&m_dctx, &sigVal[sigValLen], &t);
- sigValLen += t;
+ sigValLen += t;
- // Translate to BNs and thence to DSA_SIG
- BIGNUM * R;
- BIGNUM * S;
+ // Translate to BNs and thence to DSA_SIG
+ BIGNUM * R;
+ BIGNUM * S;
- if (sigValLen == 40) {
+ if (sigValLen == 40) {
- R = BN_bin2bn(sigVal, 20, NULL);
- S = BN_bin2bn(&sigVal[20], 20, NULL);
- }
- else {
+ R = BN_bin2bn(sigVal, 20, NULL);
+ S = BN_bin2bn(&sigVal[20], 20, NULL);
+ }
+ else {
- unsigned char rb[20];
- unsigned char sb[20];
+ unsigned char rb[20];
+ unsigned char sb[20];
- if (sigValLen == 46 && ASN2DSASig(sigVal, rb, sb) == true) {
+ if (sigValLen == 46 && ASN2DSASig(sigVal, rb, sb) == true) {
- R = BN_bin2bn(rb, 20, NULL);
- S = BN_bin2bn(sb, 20, NULL);
+ R = BN_bin2bn(rb, 20, NULL);
+ S = BN_bin2bn(sb, 20, NULL);
- }
+ }
- else {
+ else {
- throw XSECCryptoException(XSECCryptoException::DSAError,
- "OpenSSL:DSA - Signature Length incorrect");
- }
- }
+ throw XSECCryptoException(XSECCryptoException::DSAError,
+ "OpenSSL:DSA - Signature Length incorrect");
+ }
+ }
- DSA_SIG * dsa_sig = DSA_SIG_new();
+ DSA_SIG * dsa_sig = DSA_SIG_new();
- dsa_sig->r = BN_dup(R);
- dsa_sig->s = BN_dup(S);
+ dsa_sig->r = BN_dup(R);
+ dsa_sig->s = BN_dup(S);
- BN_free(R);
- BN_free(S);
+ BN_free(R);
+ BN_free(S);
- // Now we have a signature and a key - lets check
+ // Now we have a signature and a key - lets check
- int err = DSA_do_verify(hashBuf, hashLen, dsa_sig, mp_dsaKey);
+ int err = DSA_do_verify(hashBuf, hashLen, dsa_sig, mp_dsaKey);
- DSA_SIG_free(dsa_sig);
+ DSA_SIG_free(dsa_sig);
- if (err < 0) {
+ if (err < 0) {
- throw XSECCryptoException(XSECCryptoException::DSAError,
- "OpenSSL:DSA - Error validating signature");
- }
+ throw XSECCryptoException(XSECCryptoException::DSAError,
+ "OpenSSL:DSA - Error validating signature");
+ }
- return (err == 1);
+ return (err == 1);
}
@@ -252,78 +252,78 @@ bool OpenSSLCryptoKeyDSA::verifyBase64Si
unsigned int OpenSSLCryptoKeyDSA::signBase64Signature(unsigned char * hashBuf,
- unsigned int hashLen,
- char * base64SignatureBuf,
- unsigned int base64SignatureBufLen) {
+ unsigned int hashLen,
+ char * base64SignatureBuf,
+ unsigned int base64SignatureBufLen) {
- // Sign a pre-calculated hash using this key
+ // Sign a pre-calculated hash using this key
- if (mp_dsaKey == NULL) {
+ if (mp_dsaKey == NULL) {
- throw XSECCryptoException(XSECCryptoException::DSAError,
- "OpenSSL:DSA - Attempt to sign data with empty key");
- }
+ throw XSECCryptoException(XSECCryptoException::DSAError,
+ "OpenSSL:DSA - Attempt to sign data with empty key");
+ }
- DSA_SIG * dsa_sig;
+ DSA_SIG * dsa_sig;
- dsa_sig = DSA_do_sign(hashBuf, hashLen, mp_dsaKey);
+ dsa_sig = DSA_do_sign(hashBuf, hashLen, mp_dsaKey);
- if (dsa_sig == NULL) {
+ if (dsa_sig == NULL) {
- throw XSECCryptoException(XSECCryptoException::DSAError,
- "OpenSSL:DSA - Error signing data");
+ throw XSECCryptoException(XSECCryptoException::DSAError,
+ "OpenSSL:DSA - Error signing data");
- }
+ }
- // Now turn the signature into a base64 string
+ // Now turn the signature into a base64 string
- unsigned char* rawSigBuf = new unsigned char[(BN_num_bits(dsa_sig->r) + BN_num_bits(dsa_sig->s) + 7) / 8];
+ unsigned char* rawSigBuf = new unsigned char[(BN_num_bits(dsa_sig->r) + BN_num_bits(dsa_sig->s) + 7) / 8];
ArrayJanitor<unsigned char> j_sigbuf(rawSigBuf);
-
+
unsigned int rawLen = BN_bn2bin(dsa_sig->r, rawSigBuf);
- if (rawLen <= 0) {
+ if (rawLen <= 0) {
- throw XSECCryptoException(XSECCryptoException::DSAError,
- "OpenSSL:DSA - Error converting signature to raw buffer");
+ throw XSECCryptoException(XSECCryptoException::DSAError,
+ "OpenSSL:DSA - Error converting signature to raw buffer");
- }
+ }
- unsigned int rawLenS = BN_bn2bin(dsa_sig->s, (unsigned char *) &rawSigBuf[rawLen]);
+ unsigned int rawLenS = BN_bn2bin(dsa_sig->s, (unsigned char *) &rawSigBuf[rawLen]);
- if (rawLenS <= 0) {
+ if (rawLenS <= 0) {
- throw XSECCryptoException(XSECCryptoException::DSAError,
- "OpenSSL:DSA - Error converting signature to raw buffer");
+ throw XSECCryptoException(XSECCryptoException::DSAError,
+ "OpenSSL:DSA - Error converting signature to raw buffer");
- }
+ }
- rawLen += rawLenS;
+ rawLen += rawLenS;
- // Now convert to Base 64
+ // Now convert to Base 64
- BIO * b64 = BIO_new(BIO_f_base64());
- BIO * bmem = BIO_new(BIO_s_mem());
+ BIO * b64 = BIO_new(BIO_f_base64());
+ BIO * bmem = BIO_new(BIO_s_mem());
- BIO_set_mem_eof_return(bmem, 0);
- b64 = BIO_push(b64, bmem);
+ BIO_set_mem_eof_return(bmem, 0);
+ b64 = BIO_push(b64, bmem);
- // Translate signature from Base64
+ // Translate signature from Base64
- BIO_write(b64, rawSigBuf, rawLen);
- BIO_flush(b64);
+ BIO_write(b64, rawSigBuf, rawLen);
+ BIO_flush(b64);
- unsigned int sigValLen = BIO_read(bmem, base64SignatureBuf, base64SignatureBufLen);
+ unsigned int sigValLen = BIO_read(bmem, base64SignatureBuf, base64SignatureBufLen);
- BIO_free_all(b64);
+ BIO_free_all(b64);
- if (sigValLen <= 0) {
+ if (sigValLen <= 0) {
- throw XSECCryptoException(XSECCryptoException::DSAError,
- "OpenSSL:DSA - Error base64 encoding signature");
- }
+ throw XSECCryptoException(XSECCryptoException::DSAError,
+ "OpenSSL:DSA - Error base64 encoding signature");
+ }
- return sigValLen;
+ return sigValLen;
}
@@ -331,26 +331,26 @@ unsigned int OpenSSLCryptoKeyDSA::signBa
XSECCryptoKey * OpenSSLCryptoKeyDSA::clone() const {
- OpenSSLCryptoKeyDSA * ret;
+ OpenSSLCryptoKeyDSA * ret;
- XSECnew(ret, OpenSSLCryptoKeyDSA);
+ XSECnew(ret, OpenSSLCryptoKeyDSA);
- ret->m_keyType = m_keyType;
- ret->mp_dsaKey = DSA_new();
+ ret->m_keyType = m_keyType;
+ ret->mp_dsaKey = DSA_new();
- // Duplicate parameters
- if (mp_dsaKey->p)
- ret->mp_dsaKey->p = BN_dup(mp_dsaKey->p);
- if (mp_dsaKey->q)
- ret->mp_dsaKey->q = BN_dup(mp_dsaKey->q);
- if (mp_dsaKey->g)
- ret->mp_dsaKey->g = BN_dup(mp_dsaKey->g);
- if (mp_dsaKey->pub_key)
- ret->mp_dsaKey->pub_key = BN_dup(mp_dsaKey->pub_key);
- if (mp_dsaKey->priv_key)
- ret->mp_dsaKey->priv_key = BN_dup(mp_dsaKey->priv_key);
+ // Duplicate parameters
+ if (mp_dsaKey->p)
+ ret->mp_dsaKey->p = BN_dup(mp_dsaKey->p);
+ if (mp_dsaKey->q)
+ ret->mp_dsaKey->q = BN_dup(mp_dsaKey->q);
+ if (mp_dsaKey->g)
+ ret->mp_dsaKey->g = BN_dup(mp_dsaKey->g);
+ if (mp_dsaKey->pub_key)
+ ret->mp_dsaKey->pub_key = BN_dup(mp_dsaKey->pub_key);
+ if (mp_dsaKey->priv_key)
+ ret->mp_dsaKey->priv_key = BN_dup(mp_dsaKey->priv_key);
- return ret;
+ return ret;
}
Modified: santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.hpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.hpp?rev=1774662&r1=1774661&r2=1774662&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.hpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.hpp Fri Dec 16 21:18:39 2016
@@ -51,178 +51,178 @@ class DSIG_EXPORT OpenSSLCryptoKeyDSA :
public :
- /** @name Constructors and Destructors */
- //@{
-
- OpenSSLCryptoKeyDSA();
-
- /**
- * \brief Destructor
- *
- * Will call the OpenSSL function to destroy the DSA key - which will
- * also overwrite any Private keys
- */
-
- virtual ~OpenSSLCryptoKeyDSA();
-
- //@}
-
- /** @name Required Key Interface methods */
- //@{
-
- /**
- * \brief Return the type of this key.
- *
- * Allows the caller (and library) to determine whether this is a
- * public key, private key or a key pair
- */
-
- virtual XSECCryptoKey::KeyType getKeyType() const;
-
- /**
- *\brief Return the OpenSSL string identifier
- */
-
- virtual const XMLCh * getProviderName() const {return DSIGConstants::s_unicodeStrPROVOpenSSL;}
-
- /**
- * \brief Replicate key
- */
-
- virtual XSECCryptoKey * clone() const;
-
- //@}
-
- /** @name Required DSA methods */
- //@{
-
- /**
- * \brief Create a signature
- *
- * Sign the buffer using the internal private key. Will throw a DSAError
- * if the key is not set, or is not a private key.
- *
- * @param hashBuf Buffer containing the pre-calculated (binary) digest
- * @param hashLen Number of bytes of hash in the hashBuf
- * @param base64SignatureBuf Buffer to place the base64 encoded result
- * in.
- * @param base64SignatureBufLen Implementations need to ensure they do
- * not write more bytes than this into the buffer
- */
-
- virtual unsigned int signBase64Signature(unsigned char * hashBuf,
- unsigned int hashLen,
- char * base64SignatureBuf,
- unsigned int base64SignatureBufLen);
-
- /**
- * \brief Verify a signature
- *
- * The library will call this function to validate a signature
- *
- * @param hashBuf Buffer containing the pre-calculated (binary) digest
- * @param hashLen Length of the data in the digest buffer
- * @param base64Signature Buffer containing the Base64 encoded signature
- * @param sigLen Length of the data in the signature buffer
- * @returns true if the signature was valid, false otherwise
- */
-
-
- virtual bool verifyBase64Signature(unsigned char * hashBuf,
- unsigned int hashLen,
- char * base64Signature,
- unsigned int sigLen);
-
- //@}
-
- /** @name Optional Interface methods
- *
- * Have been fully implemented in the OpenSSL interface to allow interop
- * testing to occur.
- *
- */
- //@{
-
- /**
- * \brief Load P
- *
- * @param b64 Base64 encoded parameter - read from XML document
- * @param len Length of the encoded string
- */
-
- virtual void loadPBase64BigNums(const char * b64, unsigned int len);
-
- /**
- * \brief Load Q
- *
- * @param b64 Base64 encoded parameter - read from XML document
- * @param len Length of the encoded string
- */
-
- virtual void loadQBase64BigNums(const char * b64, unsigned int len);
-
- /**
- * \brief Load G
- *
- * @param b64 Base64 encoded parameter - read from XML document
- * @param len Length of the encoded string
- */
-
- virtual void loadGBase64BigNums(const char * b64, unsigned int len);
-
- /**
- * \brief Load Y
- *
- * @param b64 Base64 encoded parameter - read from XML document
- * @param len Length of the encoded string
- */
-
- virtual void loadYBase64BigNums(const char * b64, unsigned int len);
-
- /**
- * \brief Load J
- *
- * @param b64 Base64 encoded parameter - read from XML document
- * @param len Length of the encoded string
- */
-
- virtual void loadJBase64BigNums(const char * b64, unsigned int len);
-
- //@}
-
- /** @name OpenSSL Specific functions */
- //@{
-
- /**
- * \brief Library specific constructor
- *
- * Used to create a new key around an OpenSSL EVP_PKEY object
- * holding a DSA key
- */
-
- OpenSSLCryptoKeyDSA(EVP_PKEY *k);
-
- /**
- * \brief Get OpenSSL DSA structure
- */
-
- DSA * getOpenSSLDSA(void) {return mp_dsaKey;}
+ /** @name Constructors and Destructors */
+ //@{
+
+ OpenSSLCryptoKeyDSA();
/**
- * \brief Get OpenSSL DSA structure
- */
+ * \brief Destructor
+ *
+ * Will call the OpenSSL function to destroy the DSA key - which will
+ * also overwrite any Private keys
+ */
- const DSA * getOpenSSLDSA(void) const {return mp_dsaKey;}
+ virtual ~OpenSSLCryptoKeyDSA();
- //@}
- //@}
+ //@}
+
+ /** @name Required Key Interface methods */
+ //@{
+
+ /**
+ * \brief Return the type of this key.
+ *
+ * Allows the caller (and library) to determine whether this is a
+ * public key, private key or a key pair
+ */
+
+ virtual XSECCryptoKey::KeyType getKeyType() const;
+
+ /**
+ *\brief Return the OpenSSL string identifier
+ */
+
+ virtual const XMLCh * getProviderName() const {return DSIGConstants::s_unicodeStrPROVOpenSSL;}
+
+ /**
+ * \brief Replicate key
+ */
+
+ virtual XSECCryptoKey * clone() const;
+
+ //@}
+
+ /** @name Required DSA methods */
+ //@{
+
+ /**
+ * \brief Create a signature
+ *
+ * Sign the buffer using the internal private key. Will throw a DSAError
+ * if the key is not set, or is not a private key.
+ *
+ * @param hashBuf Buffer containing the pre-calculated (binary) digest
+ * @param hashLen Number of bytes of hash in the hashBuf
+ * @param base64SignatureBuf Buffer to place the base64 encoded result
+ * in.
+ * @param base64SignatureBufLen Implementations need to ensure they do
+ * not write more bytes than this into the buffer
+ */
+
+ virtual unsigned int signBase64Signature(unsigned char * hashBuf,
+ unsigned int hashLen,
+ char * base64SignatureBuf,
+ unsigned int base64SignatureBufLen);
+
+ /**
+ * \brief Verify a signature
+ *
+ * The library will call this function to validate a signature
+ *
+ * @param hashBuf Buffer containing the pre-calculated (binary) digest
+ * @param hashLen Length of the data in the digest buffer
+ * @param base64Signature Buffer containing the Base64 encoded signature
+ * @param sigLen Length of the data in the signature buffer
+ * @returns true if the signature was valid, false otherwise
+ */
+
+
+ virtual bool verifyBase64Signature(unsigned char * hashBuf,
+ unsigned int hashLen,
+ char * base64Signature,
+ unsigned int sigLen);
+
+ //@}
+
+ /** @name Optional Interface methods
+ *
+ * Have been fully implemented in the OpenSSL interface to allow interop
+ * testing to occur.
+ *
+ */
+ //@{
+
+ /**
+ * \brief Load P
+ *
+ * @param b64 Base64 encoded parameter - read from XML document
+ * @param len Length of the encoded string
+ */
+
+ virtual void loadPBase64BigNums(const char * b64, unsigned int len);
+
+ /**
+ * \brief Load Q
+ *
+ * @param b64 Base64 encoded parameter - read from XML document
+ * @param len Length of the encoded string
+ */
+
+ virtual void loadQBase64BigNums(const char * b64, unsigned int len);
+
+ /**
+ * \brief Load G
+ *
+ * @param b64 Base64 encoded parameter - read from XML document
+ * @param len Length of the encoded string
+ */
+
+ virtual void loadGBase64BigNums(const char * b64, unsigned int len);
+
+ /**
+ * \brief Load Y
+ *
+ * @param b64 Base64 encoded parameter - read from XML document
+ * @param len Length of the encoded string
+ */
+
+ virtual void loadYBase64BigNums(const char * b64, unsigned int len);
+
+ /**
+ * \brief Load J
+ *
+ * @param b64 Base64 encoded parameter - read from XML document
+ * @param len Length of the encoded string
+ */
+
+ virtual void loadJBase64BigNums(const char * b64, unsigned int len);
+
+ //@}
+
+ /** @name OpenSSL Specific functions */
+ //@{
+
+ /**
+ * \brief Library specific constructor
+ *
+ * Used to create a new key around an OpenSSL EVP_PKEY object
+ * holding a DSA key
+ */
+
+ OpenSSLCryptoKeyDSA(EVP_PKEY *k);
+
+ /**
+ * \brief Get OpenSSL DSA structure
+ */
+
+ DSA * getOpenSSLDSA(void) {return mp_dsaKey;}
+
+ /**
+ * \brief Get OpenSSL DSA structure
+ */
+
+ const DSA * getOpenSSLDSA(void) const {return mp_dsaKey;}
+
+ //@}
+ //@}
private:
- XSECCryptoKey::KeyType m_keyType;
- DSA * mp_dsaKey;
-
+ XSECCryptoKey::KeyType m_keyType;
+ DSA * mp_dsaKey;
+
};
#endif /* XSEC_HAVE_OPENSSL */
Modified: santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyEC.cpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyEC.cpp?rev=1774662&r1=1774661&r2=1774662&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyEC.cpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyEC.cpp Fri Dec 16 21:18:39 2016
@@ -53,11 +53,11 @@ OpenSSLCryptoKeyEC::OpenSSLCryptoKeyEC()
OpenSSLCryptoKeyEC::~OpenSSLCryptoKeyEC() {
- // If we have a EC_KEY, delete it
- // OpenSSL will ensure the memory holding any private key is freed.
+ // If we have a EC_KEY, delete it
+ // OpenSSL will ensure the memory holding any private key is freed.
- if (mp_ecKey)
- EC_KEY_free(mp_ecKey);
+ if (mp_ecKey)
+ EC_KEY_free(mp_ecKey);
};
@@ -65,20 +65,20 @@ OpenSSLCryptoKeyEC::~OpenSSLCryptoKeyEC(
XSECCryptoKey::KeyType OpenSSLCryptoKeyEC::getKeyType() const {
- // Find out what we have
- if (mp_ecKey == NULL)
- return KEY_NONE;
+ // Find out what we have
+ if (mp_ecKey == NULL)
+ return KEY_NONE;
- if (EC_KEY_get0_private_key(mp_ecKey) && EC_KEY_get0_public_key(mp_ecKey))
- return KEY_EC_PAIR;
+ if (EC_KEY_get0_private_key(mp_ecKey) && EC_KEY_get0_public_key(mp_ecKey))
+ return KEY_EC_PAIR;
- if (EC_KEY_get0_private_key(mp_ecKey))
- return KEY_EC_PRIVATE;
+ if (EC_KEY_get0_private_key(mp_ecKey))
+ return KEY_EC_PRIVATE;
- if (EC_KEY_get0_public_key(mp_ecKey))
- return KEY_EC_PUBLIC;
+ if (EC_KEY_get0_public_key(mp_ecKey))
+ return KEY_EC_PUBLIC;
- return KEY_NONE;
+ return KEY_NONE;
}
@@ -91,18 +91,18 @@ void OpenSSLCryptoKeyEC::loadPublicKeyBa
EC_KEY* key = EC_KEY_new_by_curve_name(static_cast<OpenSSLCryptoProvider*>(XSECPlatformUtils::g_cryptoProvider)->curveNameToNID(curveName));
- int bufLen = len;
- unsigned char * outBuf;
- XSECnew(outBuf, unsigned char[len + 1]);
- ArrayJanitor<unsigned char> j_outBuf(outBuf);
-
- XSCryptCryptoBase64 *b64;
- XSECnew(b64, XSCryptCryptoBase64);
- Janitor<XSCryptCryptoBase64> j_b64(b64);
-
- b64->decodeInit();
- bufLen = b64->decode((unsigned char *) buf, len, outBuf, len);
- bufLen += b64->decodeFinish(&outBuf[bufLen], len-bufLen);
+ int bufLen = len;
+ unsigned char * outBuf;
+ XSECnew(outBuf, unsigned char[len + 1]);
+ ArrayJanitor<unsigned char> j_outBuf(outBuf);
+
+ XSCryptCryptoBase64 *b64;
+ XSECnew(b64, XSCryptCryptoBase64);
+ Janitor<XSCryptCryptoBase64> j_b64(b64);
+
+ b64->decodeInit();
+ bufLen = b64->decode((unsigned char *) buf, len, outBuf, len);
+ bufLen += b64->decodeFinish(&outBuf[bufLen], len-bufLen);
if (bufLen > 0) {
if (o2i_ECPublicKey(&key, (const unsigned char **) &outBuf, bufLen) == NULL) {
@@ -111,12 +111,12 @@ void OpenSSLCryptoKeyEC::loadPublicKeyBa
}
}
- if (key == NULL) {
+ if (key == NULL) {
- throw XSECCryptoException(XSECCryptoException::ECError,
- "OpenSSL:EC - Error translating Base64 octets into OpenSSL EC_KEY structure");
+ throw XSECCryptoException(XSECCryptoException::ECError,
+ "OpenSSL:EC - Error translating Base64 octets into OpenSSL EC_KEY structure");
- }
+ }
mp_ecKey = key;
}
@@ -126,10 +126,10 @@ void OpenSSLCryptoKeyEC::loadPublicKeyBa
OpenSSLCryptoKeyEC::OpenSSLCryptoKeyEC(EVP_PKEY *k) {
- // Create a new key to be loaded as we go
+ // Create a new key to be loaded as we go
- if (k == NULL || k->type != EVP_PKEY_EC)
- return; // Nothing to do with us
+ if (k == NULL || k->type != EVP_PKEY_EC)
+ return; // Nothing to do with us
mp_ecKey = EC_KEY_dup(k->pkey.ec);
}
@@ -139,72 +139,72 @@ OpenSSLCryptoKeyEC::OpenSSLCryptoKeyEC(E
// --------------------------------------------------------------------------------
bool OpenSSLCryptoKeyEC::verifyBase64SignatureDSA(unsigned char * hashBuf,
- unsigned int hashLen,
- char * base64Signature,
- unsigned int sigLen) {
+ unsigned int hashLen,
+ char * base64Signature,
+ unsigned int sigLen) {
- // Use the currently loaded key to validate the Base64 encoded signature
+ // Use the currently loaded key to validate the Base64 encoded signature
- if (mp_ecKey == NULL) {
+ if (mp_ecKey == NULL) {
- throw XSECCryptoException(XSECCryptoException::ECError,
- "OpenSSL:EC - Attempt to validate signature with empty key");
- }
+ throw XSECCryptoException(XSECCryptoException::ECError,
+ "OpenSSL:EC - Attempt to validate signature with empty key");
+ }
- char * cleanedBase64Signature;
- unsigned int cleanedBase64SignatureLen = 0;
+ char * cleanedBase64Signature;
+ unsigned int cleanedBase64SignatureLen = 0;
- cleanedBase64Signature =
- XSECCryptoBase64::cleanBuffer(base64Signature, sigLen, cleanedBase64SignatureLen);
- ArrayJanitor<char> j_cleanedBase64Signature(cleanedBase64Signature);
+ cleanedBase64Signature =
+ XSECCryptoBase64::cleanBuffer(base64Signature, sigLen, cleanedBase64SignatureLen);
+ ArrayJanitor<char> j_cleanedBase64Signature(cleanedBase64Signature);
- int sigValLen;
- unsigned char* sigVal = new unsigned char[sigLen + 1];
+ int sigValLen;
+ unsigned char* sigVal = new unsigned char[sigLen + 1];
ArrayJanitor<unsigned char> j_sigVal(sigVal);
- EVP_ENCODE_CTX m_dctx;
- EVP_DecodeInit(&m_dctx);
- int rc = EVP_DecodeUpdate(&m_dctx,
- sigVal,
- &sigValLen,
- (unsigned char *) cleanedBase64Signature,
- cleanedBase64SignatureLen);
-
- if (rc < 0) {
-
- throw XSECCryptoException(XSECCryptoException::ECError,
- "OpenSSL:EC - Error during Base64 Decode");
- }
- int t = 0;
+ EVP_ENCODE_CTX m_dctx;
+ EVP_DecodeInit(&m_dctx);
+ int rc = EVP_DecodeUpdate(&m_dctx,
+ sigVal,
+ &sigValLen,
+ (unsigned char *) cleanedBase64Signature,
+ cleanedBase64SignatureLen);
- EVP_DecodeFinal(&m_dctx, &sigVal[sigValLen], &t);
+ if (rc < 0) {
- sigValLen += t;
+ throw XSECCryptoException(XSECCryptoException::ECError,
+ "OpenSSL:EC - Error during Base64 Decode");
+ }
+ int t = 0;
+
+ EVP_DecodeFinal(&m_dctx, &sigVal[sigValLen], &t);
+
+ sigValLen += t;
if (sigValLen <= 0 || sigValLen % 2 != 0) {
- throw XSECCryptoException(XSECCryptoException::ECError,
- "OpenSSL:EC - Signature length was odd");
+ throw XSECCryptoException(XSECCryptoException::ECError,
+ "OpenSSL:EC - Signature length was odd");
}
- // Translate to BNs by splitting in half, and thence to ECDSA_SIG
+ // Translate to BNs by splitting in half, and thence to ECDSA_SIG
- ECDSA_SIG * dsa_sig = ECDSA_SIG_new();
- dsa_sig->r = BN_bin2bn(sigVal, sigValLen / 2, NULL);
- dsa_sig->s = BN_bin2bn(&sigVal[sigValLen / 2], sigValLen / 2, NULL);
+ ECDSA_SIG * dsa_sig = ECDSA_SIG_new();
+ dsa_sig->r = BN_bin2bn(sigVal, sigValLen / 2, NULL);
+ dsa_sig->s = BN_bin2bn(&sigVal[sigValLen / 2], sigValLen / 2, NULL);
- // Now we have a signature and a key - lets check
+ // Now we have a signature and a key - lets check
- int err = ECDSA_do_verify(hashBuf, hashLen, dsa_sig, mp_ecKey);
+ int err = ECDSA_do_verify(hashBuf, hashLen, dsa_sig, mp_ecKey);
- ECDSA_SIG_free(dsa_sig);
+ ECDSA_SIG_free(dsa_sig);
- if (err < 0) {
+ if (err < 0) {
- throw XSECCryptoException(XSECCryptoException::ECError,
- "OpenSSL:EC - Error validating signature");
- }
+ throw XSECCryptoException(XSECCryptoException::ECError,
+ "OpenSSL:EC - Error validating signature");
+ }
- return (err == 1);
+ return (err == 1);
}
@@ -214,25 +214,25 @@ bool OpenSSLCryptoKeyEC::verifyBase64Sig
unsigned int OpenSSLCryptoKeyEC::signBase64SignatureDSA(unsigned char * hashBuf,
- unsigned int hashLen,
- char * base64SignatureBuf,
- unsigned int base64SignatureBufLen) {
+ unsigned int hashLen,
+ char * base64SignatureBuf,
+ unsigned int base64SignatureBufLen) {
- // Sign a pre-calculated hash using this key
+ // Sign a pre-calculated hash using this key
- if (mp_ecKey == NULL) {
- throw XSECCryptoException(XSECCryptoException::ECError,
- "OpenSSL:EC - Attempt to sign data with empty key");
- }
+ if (mp_ecKey == NULL) {
+ throw XSECCryptoException(XSECCryptoException::ECError,
+ "OpenSSL:EC - Attempt to sign data with empty key");
+ }
- ECDSA_SIG * dsa_sig;
+ ECDSA_SIG * dsa_sig;
- dsa_sig = ECDSA_do_sign(hashBuf, hashLen, mp_ecKey);
+ dsa_sig = ECDSA_do_sign(hashBuf, hashLen, mp_ecKey);
- if (dsa_sig == NULL) {
- throw XSECCryptoException(XSECCryptoException::ECError,
- "OpenSSL:EC - Error signing data");
- }
+ if (dsa_sig == NULL) {
+ throw XSECCryptoException(XSECCryptoException::ECError,
+ "OpenSSL:EC - Error signing data");
+ }
// To encode the signature properly, we need to know the "size of the
// base point order of the curve in bytes", which seems to correspond to the
@@ -254,63 +254,63 @@ unsigned int OpenSSLCryptoKeyEC::signBas
if (keyLen == 0) {
throw XSECCryptoException(XSECCryptoException::ECError,
- "OpenSSL:EC - Error caclulating signature size");
+ "OpenSSL:EC - Error caclulating signature size");
}
- // Now turn the signature into a raw octet string, half r and half s.
+ // Now turn the signature into a raw octet string, half r and half s.
- unsigned char* rawSigBuf = new unsigned char[keyLen * 2];
+ unsigned char* rawSigBuf = new unsigned char[keyLen * 2];
memset(rawSigBuf, 0, keyLen * 2);
ArrayJanitor<unsigned char> j_sigbuf(rawSigBuf);
unsigned int rawLen = (BN_num_bits(dsa_sig->r) + 7) / 8;
if (BN_bn2bin(dsa_sig->r, rawSigBuf + keyLen - rawLen) <= 0) {
- throw XSECCryptoException(XSECCryptoException::ECError,
- "OpenSSL:EC - Error copying signature 'r' value to buffer");
- }
+ throw XSECCryptoException(XSECCryptoException::ECError,
+ "OpenSSL:EC - Error copying signature 'r' value to buffer");
+ }
- rawLen = (BN_num_bits(dsa_sig->s) + 7) / 8;
+ rawLen = (BN_num_bits(dsa_sig->s) + 7) / 8;
if (BN_bn2bin(dsa_sig->s, rawSigBuf + keyLen + keyLen - rawLen) <= 0) {
- throw XSECCryptoException(XSECCryptoException::ECError,
- "OpenSSL:EC - Error copying signature 's' value to buffer");
- }
+ throw XSECCryptoException(XSECCryptoException::ECError,
+ "OpenSSL:EC - Error copying signature 's' value to buffer");
+ }
- // Now convert to Base 64
+ // Now convert to Base 64
- BIO * b64 = BIO_new(BIO_f_base64());
- BIO * bmem = BIO_new(BIO_s_mem());
+ BIO * b64 = BIO_new(BIO_f_base64());
+ BIO * bmem = BIO_new(BIO_s_mem());
- BIO_set_mem_eof_return(bmem, 0);
- b64 = BIO_push(b64, bmem);
+ BIO_set_mem_eof_return(bmem, 0);
+ b64 = BIO_push(b64, bmem);
- BIO_write(b64, rawSigBuf, keyLen * 2);
- BIO_flush(b64);
+ BIO_write(b64, rawSigBuf, keyLen * 2);
+ BIO_flush(b64);
- unsigned int sigValLen = BIO_read(bmem, base64SignatureBuf, base64SignatureBufLen);
+ unsigned int sigValLen = BIO_read(bmem, base64SignatureBuf, base64SignatureBufLen);
- BIO_free_all(b64);
+ BIO_free_all(b64);
- if (sigValLen <= 0) {
- throw XSECCryptoException(XSECCryptoException::ECError,
- "OpenSSL:EC - Error base64 encoding signature");
- }
+ if (sigValLen <= 0) {
+ throw XSECCryptoException(XSECCryptoException::ECError,
+ "OpenSSL:EC - Error base64 encoding signature");
+ }
- return sigValLen;
+ return sigValLen;
}
XSECCryptoKey * OpenSSLCryptoKeyEC::clone() const {
- OpenSSLCryptoKeyEC * ret;
+ OpenSSLCryptoKeyEC * ret;
- XSECnew(ret, OpenSSLCryptoKeyEC);
+ XSECnew(ret, OpenSSLCryptoKeyEC);
- ret->m_keyType = m_keyType;
+ ret->m_keyType = m_keyType;
if (mp_ecKey)
ret->mp_ecKey = EC_KEY_dup(mp_ecKey);
- return ret;
+ return ret;
}