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 2012/06/21 22:58:40 UTC

svn commit: r1352681 - in /santuario/xml-security-cpp/trunk/xsec/transformers: TXFMCipher.cpp TXFMCipher.hpp

Author: scantor
Date: Thu Jun 21 20:58:40 2012
New Revision: 1352681

URL: http://svn.apache.org/viewvc?rev=1352681&view=rev
Log:
Pass in cipher mode and tag length.

Modified:
    santuario/xml-security-cpp/trunk/xsec/transformers/TXFMCipher.cpp
    santuario/xml-security-cpp/trunk/xsec/transformers/TXFMCipher.hpp

Modified: santuario/xml-security-cpp/trunk/xsec/transformers/TXFMCipher.cpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/transformers/TXFMCipher.cpp?rev=1352681&r1=1352680&r2=1352681&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/transformers/TXFMCipher.cpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/transformers/TXFMCipher.cpp Thu Jun 21 20:58:40 2012
@@ -37,28 +37,30 @@ XERCES_CPP_NAMESPACE_USE
 
 TXFMCipher::TXFMCipher(DOMDocument *doc, 
 					   XSECCryptoKey * key, 
-					   bool encrypt) : 
+					   bool encrypt,
+                       XSECCryptoSymmetricKey::SymmetricKeyMode mode,
+                       unsigned int taglen) : 
 TXFMBase(doc),
 m_doEncrypt(encrypt),
+m_taglen(taglen),
+mp_cipher(NULL),
 m_remaining(0) {
 
-
-	mp_cipher = key->clone();
+    if (key && key->getKeyType() == XSECCryptoKey::KEY_SYMMETRIC)
+	    mp_cipher = key->clone();
 	
 	if (!mp_cipher) {
-
 		throw XSECException(XSECException::CryptoProviderError, 
-				"Error cloning key");
-
+				"Error cloning key, or not a symmetric key");
 	}
 
 	m_complete = false;
 
 	try {
-		if (mp_cipher->getKeyType() == XSECCryptoKey::KEY_SYMMETRIC && m_doEncrypt)
-			((XSECCryptoSymmetricKey *) (mp_cipher))->encryptInit();
+		if (m_doEncrypt)
+			((XSECCryptoSymmetricKey *) (mp_cipher))->encryptInit((mode != XSECCryptoSymmetricKey::MODE_GCM), mode);
 		else
-			((XSECCryptoSymmetricKey *) (mp_cipher))->decryptInit();
+			((XSECCryptoSymmetricKey *) (mp_cipher))->decryptInit((mode != XSECCryptoSymmetricKey::MODE_GCM), mode);
 	}
 	catch (...) {
 		delete mp_cipher;
@@ -70,7 +72,6 @@ m_remaining(0) {
 
 TXFMCipher::~TXFMCipher() {
 
-	if (mp_cipher != NULL)
 		delete mp_cipher;
 
 };
@@ -138,27 +139,25 @@ unsigned int TXFMCipher::readBytes(XMLBy
 
 			unsigned int sz = input->readBytes(m_inputBuffer, 2048);
 		
-			if (mp_cipher->getKeyType() == XSECCryptoKey::KEY_SYMMETRIC) {
-				XSECCryptoSymmetricKey * symCipher = 
-					(XSECCryptoSymmetricKey*) mp_cipher;
-				if (m_doEncrypt) {
+			XSECCryptoSymmetricKey * symCipher = 
+				(XSECCryptoSymmetricKey*) mp_cipher;
+			if (m_doEncrypt) {
 					
-					if (sz == 0) {
-						m_complete = true;
-						m_remaining = symCipher->encryptFinish(m_outputBuffer, 3072);
-					}
-					else
-						m_remaining = symCipher->encrypt(m_inputBuffer, m_outputBuffer, sz, 3072);
+				if (sz == 0) {
+					m_complete = true;
+					m_remaining = symCipher->encryptFinish(m_outputBuffer, 3072, m_taglen);
 				}
-				else {
+				else
+					m_remaining = symCipher->encrypt(m_inputBuffer, m_outputBuffer, sz, 3072);
+			}
+			else {
 
-					if (sz == 0) {
-						m_complete = true;
-						m_remaining = symCipher->decryptFinish(m_outputBuffer, 3072);
-					}
-					else
-						m_remaining = symCipher->decrypt(m_inputBuffer, m_outputBuffer, sz, 3072);
+				if (sz == 0) {
+					m_complete = true;
+					m_remaining = symCipher->decryptFinish(m_outputBuffer, 3072);
 				}
+				else
+					m_remaining = symCipher->decrypt(m_inputBuffer, m_outputBuffer, sz, 3072);
 			}
 		}
 

Modified: santuario/xml-security-cpp/trunk/xsec/transformers/TXFMCipher.hpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/transformers/TXFMCipher.hpp?rev=1352681&r1=1352680&r2=1352681&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/transformers/TXFMCipher.hpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/transformers/TXFMCipher.hpp Thu Jun 21 20:58:40 2012
@@ -48,7 +48,11 @@ public:
 
 	// Constructors and destructors
 
-	TXFMCipher(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc, XSECCryptoKey * key, bool encrypt);
+    TXFMCipher(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* doc,
+                XSECCryptoKey* key,
+                bool encrypt,
+                XSECCryptoSymmetricKey::SymmetricKeyMode mode = XSECCryptoSymmetricKey::MODE_CBC,
+                unsigned int taglen = 0);
 	~TXFMCipher();
 
 	// Methods to get tranform output type and input requirement
@@ -76,6 +80,7 @@ private:
 	TXFMCipher();
 
 	bool					m_doEncrypt;		// Are we in encrypt (or decrypt) mode
+    unsigned int            m_taglen;           // Length of Authentication Tag for AEAD ciphers
 	XSECCryptoKey			* mp_cipher;		// Crypto implementation
 	bool					m_complete;
 	unsigned char			m_inputBuffer[2050];