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

WinCAPICryptoSymmetricKey.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: WinCAPICryptoSymmetricKey.hpp,v 1.4 2004/02/08 10:23:33 blautenb Exp $
00026  *
00027  */
00028 
00029 
00030 
00031 #ifndef WINCAPICRYPTOSYMMETRICKEY_INCLUDE
00032 #define WINCAPICRYPTOSYMMETRICKEY_INCLUDE
00033 
00034 #include <xsec/framework/XSECDefs.hpp>
00035 #include <xsec/enc/XSECCryptoSymmetricKey.hpp>
00036 
00037 #if defined (HAVE_WINCAPI)
00038 
00039 #if !defined(_WIN32_WINNT)
00040 #   define _WIN32_WINNT 0x0400
00041 #endif
00042 
00043 #include <wincrypt.h>
00044 
00045 #define WINCAPI_MAX_BLOCK_SIZE      32
00046 
00059 class DSIG_EXPORT WinCAPICryptoSymmetricKey : public XSECCryptoSymmetricKey {
00060 
00061 public :
00062 
00065     
00077     WinCAPICryptoSymmetricKey(HCRYPTPROV prov, XSECCryptoSymmetricKey::SymmetricKeyType type);
00078 
00086     virtual ~WinCAPICryptoSymmetricKey();
00087 
00089 
00092 
00097     virtual const XMLCh * getProviderName();
00098 
00107     virtual XSECCryptoKey * clone();
00108 
00110 
00113 
00122     SymmetricKeyType getSymmetricKeyType(void);
00123 
00135     void setKey(const unsigned char * key, unsigned int keyLen);
00136 
00153     virtual bool decryptInit(bool doPad = true,
00154                              SymmetricKeyMode mode = MODE_CBC,
00155                              const unsigned char * iv = NULL);
00156 
00181     virtual unsigned int decrypt(const unsigned char * inBuf, 
00182                                  unsigned char * plainBuf, 
00183                                  unsigned int inLength,
00184                                  unsigned int maxOutLength);
00185 
00205     virtual unsigned int decryptFinish(unsigned char * plainBuf,
00206                                        unsigned int maxOutLength);
00207 
00223     virtual bool encryptInit(bool doPad = true, 
00224                              SymmetricKeyMode mode = MODE_CBC,
00225                              const unsigned char * iv = NULL);
00226 
00247     virtual unsigned int encrypt(const unsigned char * inBuf, 
00248                                  unsigned char * cipherBuf, 
00249                                  unsigned int inLength,
00250                                  unsigned int maxOutLength);
00251 
00273     virtual unsigned int encryptFinish(unsigned char * plainBuf,
00274                                        unsigned int maxOutLength);
00275 
00277 
00280 
00299     static HCRYPTKEY createWindowsKey(const unsigned char * key, 
00300                                       unsigned int keyLen, 
00301                                       XSECCryptoSymmetricKey::SymmetricKeyType type,
00302                                       HCRYPTPROV * prov);
00303 
00304 
00305 
00306 private:
00307 
00308     // Unimplemented constructors
00309     
00310     WinCAPICryptoSymmetricKey();
00311     WinCAPICryptoSymmetricKey(const WinCAPICryptoSymmetricKey &);
00312     WinCAPICryptoSymmetricKey & operator= (const WinCAPICryptoSymmetricKey &);
00313 
00314     int decryptCtxInit(const unsigned char * iv);
00315     void encryptCtxInit(const unsigned char * iv);
00316 
00317     // Private variables
00318     SymmetricKeyType                m_keyType;
00319     SymmetricKeyMode                m_keyMode;      // ECB or CBC
00320     safeBuffer                      m_keyBuf;       // Holder of the key
00321     unsigned int                    m_keyLen;
00322     bool                            m_initialised;
00323     bool                            m_doPad;
00324 
00325     unsigned char                   m_lastBlock[WINCAPI_MAX_BLOCK_SIZE];
00326     unsigned int                    m_bytesInLastBlock;
00327     unsigned int                    m_blockSize;
00328     unsigned int                    m_ivSize;
00329 
00330     HCRYPTPROV                      m_p;
00331     HCRYPTKEY                       m_k;
00332 
00333 };
00334 
00335 #endif /* HAVE_WINCAPI */
00336 #endif /* WINCAPICRYPTOSYMMETRICKEY_INCLUDE */

Generated on Sun Mar 14 21:35:31 2004 for XML-Security-C by doxygen 1.3.2