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

OpenSSLCryptoSymmetricKey.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2002-2004 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  * imitations 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.8 2004/02/08 10:22:50 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 
00057 class DSIG_EXPORT OpenSSLCryptoSymmetricKey : public XSECCryptoSymmetricKey {
00058 
00059 public :
00060 
00063     
00070     OpenSSLCryptoSymmetricKey(XSECCryptoSymmetricKey::SymmetricKeyType type);
00071 
00079     virtual ~OpenSSLCryptoSymmetricKey();
00080 
00082 
00085 
00090     virtual const XMLCh * getProviderName();
00091 
00100     virtual XSECCryptoKey * clone();
00101 
00103 
00106 
00115     SymmetricKeyType getSymmetricKeyType(void);
00116 
00128     void setKey(const unsigned char * key, unsigned int keyLen);
00129 
00146     virtual bool decryptInit(bool doPad = true,
00147                              SymmetricKeyMode mode = MODE_CBC,
00148                              const unsigned char * iv = NULL);
00149 
00174     virtual unsigned int decrypt(const unsigned char * inBuf, 
00175                                  unsigned char * plainBuf, 
00176                                  unsigned int inLength,
00177                                  unsigned int maxOutLength);
00178 
00198     virtual unsigned int decryptFinish(unsigned char * plainBuf,
00199                                        unsigned int maxOutLength);
00200 
00216     virtual bool encryptInit(bool doPad = true, 
00217                              SymmetricKeyMode mode = MODE_CBC,
00218                              const unsigned char * iv = NULL);
00219 
00240     virtual unsigned int encrypt(const unsigned char * inBuf, 
00241                                  unsigned char * cipherBuf, 
00242                                  unsigned int inLength,
00243                                  unsigned int maxOutLength);
00244 
00266     virtual unsigned int encryptFinish(unsigned char * plainBuf,
00267                                        unsigned int maxOutLength);
00268 
00270 
00271 private:
00272 
00273     // Unimplemented constructors
00274     
00275     OpenSSLCryptoSymmetricKey();
00276     OpenSSLCryptoSymmetricKey(const OpenSSLCryptoSymmetricKey &);
00277     OpenSSLCryptoSymmetricKey & operator= (const OpenSSLCryptoSymmetricKey &);
00278 
00279     // Private functions
00280     int decryptCtxInit(const unsigned char * iv);
00281 
00282     // Private variables
00283     SymmetricKeyType                m_keyType;
00284     SymmetricKeyMode                m_keyMode;
00285     EVP_CIPHER_CTX                  m_ctx;          // OpenSSL Cipher Context structure
00286     safeBuffer                      m_keyBuf;       // Holder of the key
00287     unsigned int                    m_keyLen;
00288     bool                            m_initialised;  // Is the context ready to work?
00289     unsigned char                   m_lastBlock[MAX_BLOCK_SIZE];
00290     int                             m_blockSize;
00291     int                             m_ivSize;
00292     int                             m_bytesInLastBlock;
00293     bool                            m_ivSent;       // Has the IV been put in the stream
00294     bool                            m_doPad;        // Do we pad last block?
00295 };
00296 
00297 #endif /* HAVE_OPENSSL */
00298 #endif /* OPENSSLCRYPTOSYMMETRICKEY_INCLUDE */

Generated on Sun Mar 14 20:20:36 2004 for XML-Security-C by doxygen 1.3.2