You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by bl...@apache.org on 2005/02/20 11:35:14 UTC
cvs commit: xml-security/c/src/enc/WinCAPI WinCAPICryptoHash.cpp WinCAPICryptoProvider.cpp WinCAPICryptoProvider.hpp
blautenb 2005/02/20 02:35:14
Modified: c/src/enc XSECCryptoHash.hpp XSECCryptoProvider.hpp
c/src/enc/OpenSSL OpenSSLCryptoHash.cpp
OpenSSLCryptoHashHMAC.cpp OpenSSLCryptoProvider.cpp
OpenSSLCryptoProvider.hpp
c/src/enc/WinCAPI WinCAPICryptoHash.cpp
WinCAPICryptoProvider.cpp WinCAPICryptoProvider.hpp
Log:
Add interface for SHA224/256/384/512
Revision Changes Path
1.11 +6 -2 xml-security/c/src/enc/XSECCryptoHash.hpp
Index: XSECCryptoHash.hpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/enc/XSECCryptoHash.hpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- XSECCryptoHash.hpp 3 Feb 2005 12:48:16 -0000 1.10
+++ XSECCryptoHash.hpp 20 Feb 2005 10:35:14 -0000 1.11
@@ -69,7 +69,11 @@
HASH_NONE = 0,
HASH_SHA1 = 1,
- HASH_MD5 = 2
+ HASH_MD5 = 2,
+ HASH_SHA224 = 3,
+ HASH_SHA256 = 4,
+ HASH_SHA384 = 5,
+ HASH_SHA512 = 6
};
1.17 +39 -1 xml-security/c/src/enc/XSECCryptoProvider.hpp
Index: XSECCryptoProvider.hpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/enc/XSECCryptoProvider.hpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- XSECCryptoProvider.hpp 3 Feb 2005 12:48:16 -0000 1.16
+++ XSECCryptoProvider.hpp 20 Feb 2005 10:35:14 -0000 1.17
@@ -157,11 +157,25 @@
*
* @returns A pointer to a Hash object that implements SHA1
* @see XSECCryptoHash
+ * @deprecated Use hashSHA instead
*/
virtual XSECCryptoHash * hashSHA1() = 0;
/**
+ * \brief Return a SHA implementation.
+ *
+ * Call used by the library to obtain a SHA object from the
+ * provider. Size of hash determined by length argument (160 = SHA1)
+ *
+ * @returns A pointer to a Hash object that implements SHA1
+ * @param length - length of hash. E.g. 160 for SHA1 or 256 for SHA256
+ * @see XSECCryptoHash
+ */
+
+ virtual XSECCryptoHash * hashSHA(int length = 160) = 0;
+
+ /**
* \brief Return a HMAC SHA1 implementation.
*
* Call used by the library to obtain a HMAC SHA1 object from the
@@ -170,11 +184,26 @@
*
* @returns A pointer to a Hash object that implements HMAC-SHA1
* @see XSECCryptoHash
+ * @deprecated use hashHMACSHA instead
*/
virtual XSECCryptoHash * hashHMACSHA1() = 0;
/**
+ * \brief Return a HMAC SHA(1-512) implementation.
+ *
+ * Call used by the library to obtain a HMAC SHA object from the
+ * provider. The caller will need to set the key in the hash
+ * object with an XSECCryptoKeyHMAC using XSECCryptoHash::setKey()
+ *
+ * @returns A pointer to a Hash object that implements HMAC-SHA1
+ * @length Length of hash output (160 = SHA1, 256, 512 etc)
+ * @see XSECCryptoHash
+ */
+
+ virtual XSECCryptoHash * hashHMACSHA(int length = 160) = 0;
+
+ /**
* \brief Return a MD5 implementation.
*
* Call used by the library to obtain a MD5 object from the
@@ -281,6 +310,15 @@
virtual bool algorithmSupported(XSECCryptoSymmetricKey::SymmetricKeyType alg) = 0;
/**
+ * \brief Determine whether a given algorithm is supported
+ *
+ * A call that can be used to determine whether a given
+ * digest algorithm is supported
+ */
+
+ virtual bool algorithmSupported(XSECCryptoHash::HashType alg) = 0;
+
+ /**
* \brief Return a Symmetric Key implementation object.
*
* Call used by the library to obtain a bulk encryption
1.8 +42 -2 xml-security/c/src/enc/OpenSSL/OpenSSLCryptoHash.cpp
Index: OpenSSLCryptoHash.cpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/enc/OpenSSL/OpenSSLCryptoHash.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- OpenSSLCryptoHash.cpp 3 Feb 2005 13:13:08 -0000 1.7
+++ OpenSSLCryptoHash.cpp 20 Feb 2005 10:35:14 -0000 1.8
@@ -49,6 +49,46 @@
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;
@@ -110,4 +150,4 @@
}
-#endif /* HAVE_OPENSSL */
\ No newline at end of file
+#endif /* HAVE_OPENSSL */
1.9 +41 -1 xml-security/c/src/enc/OpenSSL/OpenSSLCryptoHashHMAC.cpp
Index: OpenSSLCryptoHashHMAC.cpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/enc/OpenSSL/OpenSSLCryptoHashHMAC.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- OpenSSLCryptoHashHMAC.cpp 3 Feb 2005 13:13:08 -0000 1.8
+++ OpenSSLCryptoHashHMAC.cpp 20 Feb 2005 10:35:14 -0000 1.9
@@ -53,6 +53,46 @@
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;
1.17 +78 -1 xml-security/c/src/enc/OpenSSL/OpenSSLCryptoProvider.cpp
Index: OpenSSLCryptoProvider.cpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/enc/OpenSSL/OpenSSLCryptoProvider.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- OpenSSLCryptoProvider.cpp 3 Feb 2005 13:13:08 -0000 1.16
+++ OpenSSLCryptoProvider.cpp 20 Feb 2005 10:35:14 -0000 1.17
@@ -92,6 +92,55 @@
}
+XSECCryptoHash * OpenSSLCryptoProvider::hashSHA(int length) {
+
+
+ OpenSSLCryptoHash * ret;
+
+ switch (length) {
+
+ case 160: XSECnew(ret, OpenSSLCryptoHash(XSECCryptoHash::HASH_SHA1));
+ break;
+ case 224: XSECnew(ret, OpenSSLCryptoHash(XSECCryptoHash::HASH_SHA224));
+ break;
+ case 256: XSECnew(ret, OpenSSLCryptoHash(XSECCryptoHash::HASH_SHA256));
+ break;
+ case 384: XSECnew(ret, OpenSSLCryptoHash(XSECCryptoHash::HASH_SHA384));
+ break;
+ case 512: XSECnew(ret, OpenSSLCryptoHash(XSECCryptoHash::HASH_SHA512));
+ break;
+ default:
+ ret = NULL;
+ }
+
+ return ret;
+
+}
+
+XSECCryptoHash * OpenSSLCryptoProvider::hashHMACSHA(int length) {
+
+ OpenSSLCryptoHashHMAC * ret;
+
+ switch (length) {
+
+ case 160: XSECnew(ret, OpenSSLCryptoHashHMAC(XSECCryptoHash::HASH_SHA1));
+ break;
+ case 224: XSECnew(ret, OpenSSLCryptoHashHMAC(XSECCryptoHash::HASH_SHA224));
+ break;
+ case 256: XSECnew(ret, OpenSSLCryptoHashHMAC(XSECCryptoHash::HASH_SHA256));
+ break;
+ case 384: XSECnew(ret, OpenSSLCryptoHashHMAC(XSECCryptoHash::HASH_SHA384));
+ break;
+ case 512: XSECnew(ret, OpenSSLCryptoHashHMAC(XSECCryptoHash::HASH_SHA512));
+ break;
+ default:
+ ret = NULL;
+ }
+
+ return ret;
+
+}
+
XSECCryptoHash * OpenSSLCryptoProvider::hashMD5() {
OpenSSLCryptoHash * ret;
@@ -192,6 +241,34 @@
}
+bool OpenSSLCryptoProvider::algorithmSupported(XSECCryptoHash::HashType alg) {
+
+ switch (alg) {
+
+ case (XSECCryptoHash::HASH_SHA1) :
+ case (XSECCryptoHash::HASH_MD5) :
+
+ return true;
+
+ case (XSECCryptoHash::HASH_SHA224) :
+ case (XSECCryptoHash::HASH_SHA256) :
+ case (XSECCryptoHash::HASH_SHA384) :
+ case (XSECCryptoHash::HASH_SHA512) :
+
+ return
+#if defined (SHA512_DIGEST_LENGTH) && !defined (OPENSSL_NO_SHA512)
+ true;
+#else
+ false;
+#endif
+
+ default:
+ return false;
+ }
+
+ return false;
+
+}
XSECCryptoSymmetricKey * OpenSSLCryptoProvider::keySymmetric(XSECCryptoSymmetricKey::SymmetricKeyType alg) {
1.14 +37 -1 xml-security/c/src/enc/OpenSSL/OpenSSLCryptoProvider.hpp
Index: OpenSSLCryptoProvider.hpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/enc/OpenSSL/OpenSSLCryptoProvider.hpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- OpenSSLCryptoProvider.hpp 3 Feb 2005 13:13:08 -0000 1.13
+++ OpenSSLCryptoProvider.hpp 20 Feb 2005 10:35:14 -0000 1.14
@@ -76,6 +76,19 @@
virtual XSECCryptoHash * hashSHA1();
/**
+ * \brief Return a SHA implementation.
+ *
+ * Call used by the library to obtain a SHA object from the
+ * provider. Size of hash determined by length argument (160 = SHA1)
+ *
+ * @returns A pointer to a Hash object that implements SHA1
+ * @param length - length of hash. E.g. 160 for SHA1 or 256 for SHA256
+ * @see OpenSSLCryptoHash
+ */
+
+ virtual XSECCryptoHash * hashSHA(int length = 160);
+
+ /**
* \brief Return a HMAC SHA1 implementation.
*
* Call used by the library to obtain a HMAC SHA1 object from the
@@ -89,6 +102,20 @@
virtual XSECCryptoHash * hashHMACSHA1();
/**
+ * \brief Return a HMAC SHA(1-512) implementation.
+ *
+ * Call used by the library to obtain a HMAC SHA object from the
+ * provider. The caller will need to set the key in the hash
+ * object with an XSECCryptoKeyHMAC using XSECCryptoHash::setKey()
+ *
+ * @returns A pointer to a Hash object that implements HMAC-SHA1
+ * @length Length of hash output (160 = SHA1, 256, 512 etc)
+ * @see OpenSSLCryptoHash
+ */
+
+ virtual XSECCryptoHash * hashHMACSHA(int length = 160);
+
+ /**
* \brief Return a MD5 implementation.
*
* Call used by the library to obtain a MD5 object from the
@@ -196,6 +223,15 @@
virtual bool algorithmSupported(XSECCryptoSymmetricKey::SymmetricKeyType alg);
/**
+ * \brief Determine whether a given algorithm is supported
+ *
+ * A call that can be used to determine whether a given
+ * digest algorithm is supported
+ */
+
+ virtual bool algorithmSupported(XSECCryptoHash::HashType alg);
+
+ /**
* \brief Return a Symmetric Key implementation object.
*
* Call used by the library to obtain a bulk encryption
1.7 +2 -2 xml-security/c/src/enc/WinCAPI/WinCAPICryptoHash.cpp
Index: WinCAPICryptoHash.cpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/enc/WinCAPI/WinCAPICryptoHash.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- WinCAPICryptoHash.cpp 3 Feb 2005 13:20:37 -0000 1.6
+++ WinCAPICryptoHash.cpp 20 Feb 2005 10:35:14 -0000 1.7
@@ -84,7 +84,7 @@
if(alg_id == 0) {
throw XSECCryptoException(XSECCryptoException::MDError,
- "WinCAPI:Hash - Unknown algorithm");
+ "WinCAPI:Hash - Unknown algorithm (NOTE SHA512 and SHA256 not supported");
}
fResult = CryptCreateHash(
1.17 +43 -1 xml-security/c/src/enc/WinCAPI/WinCAPICryptoProvider.cpp
Index: WinCAPICryptoProvider.cpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/enc/WinCAPI/WinCAPICryptoProvider.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- WinCAPICryptoProvider.cpp 18 Feb 2005 10:04:16 -0000 1.16
+++ WinCAPICryptoProvider.cpp 20 Feb 2005 10:35:14 -0000 1.17
@@ -181,6 +181,24 @@
}
+XSECCryptoHash * WinCAPICryptoProvider::hashSHA(int length) {
+
+
+ if (length == 160)
+ return hashSHA1();
+
+ else return NULL;
+}
+
+XSECCryptoHash * WinCAPICryptoProvider::hashHMACSHA(int length) {
+
+ if (length == 160)
+ return hashHMACSHA1();
+
+ else return NULL;
+
+}
+
XSECCryptoHash * WinCAPICryptoProvider::hashMD5() {
WinCAPICryptoHash * ret;
@@ -279,6 +297,30 @@
}
+bool WinCAPICryptoProvider::algorithmSupported(XSECCryptoHash::HashType alg) {
+
+ switch (alg) {
+
+ case (XSECCryptoHash::HASH_SHA1) :
+ case (XSECCryptoHash::HASH_MD5) :
+
+ return true;
+
+ case (XSECCryptoHash::HASH_SHA224) :
+ case (XSECCryptoHash::HASH_SHA256) :
+ case (XSECCryptoHash::HASH_SHA384) :
+ case (XSECCryptoHash::HASH_SHA512) :
+
+ return false;
+
+ default:
+ return false;
+ }
+
+ return false;
+
+}
+
XSECCryptoSymmetricKey * WinCAPICryptoProvider::keySymmetric(XSECCryptoSymmetricKey::SymmetricKeyType alg) {
// Only temporary
1.17 +37 -1 xml-security/c/src/enc/WinCAPI/WinCAPICryptoProvider.hpp
Index: WinCAPICryptoProvider.hpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/enc/WinCAPI/WinCAPICryptoProvider.hpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- WinCAPICryptoProvider.hpp 18 Feb 2005 10:04:16 -0000 1.16
+++ WinCAPICryptoProvider.hpp 20 Feb 2005 10:35:14 -0000 1.17
@@ -124,6 +124,19 @@
virtual XSECCryptoHash * hashSHA1();
/**
+ * \brief Return a SHA implementation.
+ *
+ * Call used by the library to obtain a SHA object from the
+ * provider. Size of hash determined by length argument (160 = SHA1)
+ *
+ * @returns A pointer to a Hash object that implements SHA1
+ * @param length - length of hash. E.g. 160 for SHA1 or 256 for SHA256
+ * @see WinCAPICryptoHash
+ */
+
+ virtual XSECCryptoHash * hashSHA(int length = 160);
+
+ /**
* \brief Return a HMAC SHA1 implementation.
*
* Call used by the library to obtain a HMAC SHA1 object from the
@@ -137,6 +150,20 @@
virtual XSECCryptoHash * hashHMACSHA1();
/**
+ * \brief Return a HMAC SHA(1-512) implementation.
+ *
+ * Call used by the library to obtain a HMAC SHA object from the
+ * provider. The caller will need to set the key in the hash
+ * object with an XSECCryptoKeyHMAC using XSECCryptoHash::setKey()
+ *
+ * @returns A pointer to a Hash object that implements HMAC-SHA1
+ * @length Length of hash output (160 = SHA1, 256, 512 etc)
+ * @see WinCAPICryptoHash
+ */
+
+ virtual XSECCryptoHash * hashHMACSHA(int length = 160);
+
+ /**
* \brief Return a MD5 implementation.
*
* Call used by the library to obtain a MD5 object from the
@@ -299,6 +326,15 @@
virtual bool algorithmSupported(XSECCryptoSymmetricKey::SymmetricKeyType alg);
/**
+ * \brief Determine whether a given algorithm is supported
+ *
+ * A call that can be used to determine whether a given
+ * digest algorithm is supported
+ */
+
+ virtual bool algorithmSupported(XSECCryptoHash::HashType alg);
+
+ /**
* \brief Return a Symmetric Key implementation object.
*
* Call used by the library to obtain a bulk encryption