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 2003/10/13 13:08:39 UTC

cvs commit: xml-security/c/src/xenc/impl XENCAlgorithmHandlerDefault.cpp XENCCipherImpl.cpp

blautenb    2003/10/13 04:08:39

  Modified:    c/src/xenc/impl XENCAlgorithmHandlerDefault.cpp
                        XENCCipherImpl.cpp
  Log:
  Implementation of Symmetric Encryption in WinCAPI
  
  Revision  Changes    Path
  1.3       +6 -6      xml-security/c/src/xenc/impl/XENCAlgorithmHandlerDefault.cpp
  
  Index: XENCAlgorithmHandlerDefault.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCAlgorithmHandlerDefault.cpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XENCAlgorithmHandlerDefault.cpp	3 Oct 2003 09:50:05 -0000	1.2
  +++ XENCAlgorithmHandlerDefault.cpp	13 Oct 2003 11:08:39 -0000	1.3
  @@ -179,7 +179,7 @@
   			aesBuf[7] ^= ((n * j) + i);
   
   			// do decrypt
  -			sk->decryptInit();
  +			sk->decryptInit(false);		// No padding
   			int sz = sk->decrypt(aesBuf, aesOutBuf, 16, 16);
   			sz += sk->decryptFinish(&aesOutBuf[sz], 16 - sz);
   
  @@ -218,7 +218,7 @@
   	XMLByte buf[_MY_MAX_KEY_SIZE + 8];
   	memcpy(buf, s_AES_IV, 8);
   	XMLByte aesBuf[16];
  -	XMLByte aesOutBuf[16];
  +	XMLByte aesOutBuf[32];  // Give this an extra block for WinCAPI
   	TXFMBase * b = cipherText->getLastTxfm();
   	int sz = b->readBytes(&buf[8], _MY_MAX_KEY_SIZE);
   
  @@ -255,9 +255,9 @@
   			memcpy(&aesBuf[8], &buf[8 * i], 8);
   
   			// do encrypt
  -			sk->encryptInit();
  -			int sz = sk->encrypt(aesBuf, aesOutBuf, 16, 16);
  -			sz += sk->encryptFinish(&aesOutBuf[sz], 16 - sz);
  +			sk->encryptInit(false);
  +			int sz = sk->encrypt(aesBuf, aesOutBuf, 16, 32);
  +			sz += sk->encryptFinish(&aesOutBuf[sz], 32 - sz);
   
   			if (sz != 16) {
   				throw XSECException(XSECException::CipherError, 
  
  
  
  1.8       +27 -18    xml-security/c/src/xenc/impl/XENCCipherImpl.cpp
  
  Index: XENCCipherImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCCipherImpl.cpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XENCCipherImpl.cpp	6 Oct 2003 12:16:37 -0000	1.7
  +++ XENCCipherImpl.cpp	13 Oct 2003 11:08:39 -0000	1.8
  @@ -412,28 +412,37 @@
   				if (kil->item(i)->getKeyInfoType() == DSIGKeyInfo::KEYINFO_ENCRYPTEDKEY) {
   
   					XENCEncryptedKey * ek = dynamic_cast<XENCEncryptedKey*>(kil->item(i));
  -					XMLByte buffer[1024];
  -					int keySize = decryptKey(ek, buffer, 1024);
  +					volatile XMLByte buffer[1024];
  +					try {
  +						// Have to cast off volatile
  +						int keySize = decryptKey(ek, (XMLByte *) buffer, 1024);
   
  -					if (keySize > 0) {
  -						// Try to map the key
  +						if (keySize > 0) {
  +							// Try to map the key
   
  -						XENCEncryptionMethod * encryptionMethod = 
  -							mp_encryptedData->getEncryptionMethod();
  +							XENCEncryptionMethod * encryptionMethod = 
  +								mp_encryptedData->getEncryptionMethod();
   
  -						if (encryptionMethod != NULL) {
  -		
  -							handler = 
  -								XSECPlatformUtils::g_algorithmMapper->mapURIToHandler(
  -									mp_encryptedData->getEncryptionMethod()->getAlgorithm());
  +							if (encryptionMethod != NULL) {
  +			
  +								handler = 
  +									XSECPlatformUtils::g_algorithmMapper->mapURIToHandler(
  +										mp_encryptedData->getEncryptionMethod()->getAlgorithm());
   
  -							if (handler != NULL)
  -								mp_key = handler->createKeyForURI(
  -											mp_encryptedData->getEncryptionMethod()->getAlgorithm(),
  -											buffer,
  -											keySize);
  +								if (handler != NULL)
  +									mp_key = handler->createKeyForURI(
  +												mp_encryptedData->getEncryptionMethod()->getAlgorithm(),
  +												(XMLByte *) buffer,
  +												keySize);
  +							}
   						}
  +					} catch (...) {
  +						memset((void *) buffer, 0, 1024);
  +						throw;
   					}
  +
  +					// Clear out the key buffer
  +					memset((void *) buffer, 0, 1024);
   				}
   			}
   		}