Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

OpenSSLCryptoSymmetricKey.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2002-2005 The Apache Software Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 /*
00018  * XSEC
00019  *
00020  * XSECCryptoSymmetricKey := Bulk encryption algorithms should all be
00021  *                          implemented via this interface
00022  *
00023  * Author(s): Berin Lautenbach
00024  *
00025  * $Id: OpenSSLCryptoSymmetricKey.hpp,v 1.10 2005/06/04 11:30:26 blautenb Exp $
00026  *
00027  */
00028 
00029 
00030 
00031 #ifndef OPENSSLCRYPTOSYMMETRICKEY_INCLUDE
00032 #define OPENSSLCRYPTOSYMMETRICKEY_INCLUDE
00033 
00034 #include <xsec/framework/XSECDefs.hpp>
00035 #include <xsec/enc/XSECCryptoSymmetricKey.hpp>
00036 
00037 #if defined (HAVE_OPENSSL)
00038 
00039 // OpenSSL Includes
00040 
00041 #include <openssl/evp.h>
00042 
00043 #define MAX_BLOCK_SIZE      32
00044 
00056 class DSIG_EXPORT OpenSSLCryptoSymmetricKey : public XSECCryptoSymmetricKey {
00057 
00058 public :
00059 
00062     
00069     OpenSSLCryptoSymmetricKey(XSECCryptoSymmetricKey::SymmetricKeyType type);
00070 
00078     virtual ~OpenSSLCryptoSymmetricKey();
00079 
00081 
00084 
00089     virtual const XMLCh * getProviderName();
00090 
00099     virtual XSECCryptoKey * clone();
00100 
00102 
00105 
00114     SymmetricKeyType getSymmetricKeyType(void);
00115 
00127     void setKey(const unsigned char * key, unsigned int keyLen);
00128 
00145     virtual bool decryptInit(bool doPad = true,
00146                              SymmetricKeyMode mode = MODE_CBC,
00147                              const unsigned char * iv = NULL);
00148 
00173     virtual unsigned int decrypt(const unsigned char * inBuf, 
00174                                  unsigned char * plainBuf, 
00175                                  unsigned int inLength,
00176                                  unsigned int maxOutLength);
00177 
00197     virtual unsigned int decryptFinish(unsigned char * plainBuf,
00198                                        unsigned int maxOutLength);
00199 
00215     virtual bool encryptInit(bool doPad = true, 
00216                              SymmetricKeyMode mode = MODE_CBC,
00217                              const unsigned char * iv = NULL);
00218 
00239     virtual unsigned int encrypt(const unsigned char * inBuf, 
00240                                  unsigned char * cipherBuf, 
00241                                  unsigned int inLength,
00242                                  unsigned int maxOutLength);
00243 
00265     virtual unsigned int encryptFinish(unsigned char * plainBuf,
00266                                        unsigned int maxOutLength);
00267 
00269 
00270 private:
00271 
00272     // Unimplemented constructors
00273     
00274     OpenSSLCryptoSymmetricKey();
00275     OpenSSLCryptoSymmetricKey(const OpenSSLCryptoSymmetricKey &);
00276     OpenSSLCryptoSymmetricKey & operator= (const OpenSSLCryptoSymmetricKey &);
00277 
00278     // Private functions
00279     int decryptCtxInit(const unsigned char * iv);
00280 
00281     // Private variables
00282     SymmetricKeyType                m_keyType;
00283     SymmetricKeyMode                m_keyMode;
00284     EVP_CIPHER_CTX                  m_ctx;          // OpenSSL Cipher Context structure
00285     safeBuffer                      m_keyBuf;       // Holder of the key
00286     unsigned int                    m_keyLen;
00287     bool                            m_initialised;  // Is the context ready to work?
00288     unsigned char                   m_lastBlock[MAX_BLOCK_SIZE];
00289     int                             m_blockSize;
00290     int                             m_ivSize;
00291     int                             m_bytesInLastBlock;
00292     bool                            m_ivSent;       // Has the IV been put in the stream
00293     bool                            m_doPad;        // Do we pad last block?
00294 };
00295 
00296 #endif /* HAVE_OPENSSL */
00297 #endif /* OPENSSLCRYPTOSYMMETRICKEY_INCLUDE */

Generated on Sun Jul 3 17:37:26 2005 for XML-Security-C by  doxygen 1.4.2