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

NSSCryptoSymmetricKey.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 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): Milan Tomic
00024  *
00025  */
00026 
00027 #ifndef NSSCRYPTOSYMMETRICKEY_INCLUDE
00028 #define NSSCRYPTOSYMMETRICKEY_INCLUDE
00029 
00030 #include <xsec/framework/XSECDefs.hpp>
00031 #include <xsec/enc/XSECCryptoSymmetricKey.hpp>
00032 
00033 #if defined (HAVE_NSS)
00034 
00035 #include "nss/pk11func.h"
00036 #include "nss/nss.h"
00037 
00038 #define NSS_MAX_BLOCK_SIZE      32
00039 
00052 class DSIG_EXPORT NSSCryptoSymmetricKey : public XSECCryptoSymmetricKey {
00053 
00054 public :
00055 
00058     
00067     NSSCryptoSymmetricKey(XSECCryptoSymmetricKey::SymmetricKeyType type);
00068 
00076     virtual ~NSSCryptoSymmetricKey();
00077 
00079 
00082 
00087     virtual const XMLCh * getProviderName();
00088 
00097     virtual XSECCryptoKey * clone();
00098 
00100 
00103 
00112     SymmetricKeyType getSymmetricKeyType(void);
00113 
00125     void setKey(const unsigned char * key, unsigned int keyLen);
00126 
00143     virtual bool decryptInit(bool doPad = true,
00144                              SymmetricKeyMode mode = MODE_CBC,
00145                              const unsigned char * iv = NULL);
00146 
00171     virtual unsigned int decrypt(const unsigned char * inBuf, 
00172                                  unsigned char * plainBuf, 
00173                                  unsigned int inLength,
00174                                  unsigned int maxOutLength);
00175 
00195     virtual unsigned int decryptFinish(unsigned char * plainBuf,
00196                                        unsigned int maxOutLength);
00197 
00213     virtual bool encryptInit(bool doPad = true, 
00214                              SymmetricKeyMode mode = MODE_CBC,
00215                              const unsigned char * iv = NULL);
00216 
00237     virtual unsigned int encrypt(const unsigned char * inBuf, 
00238                                  unsigned char * cipherBuf, 
00239                                  unsigned int inLength,
00240                                  unsigned int maxOutLength);
00241 
00263     virtual unsigned int encryptFinish(unsigned char * plainBuf,
00264                                        unsigned int maxOutLength);
00265 
00267 
00268 private:
00269 
00270     // Unimplemented constructors
00271     
00272     NSSCryptoSymmetricKey();
00273     NSSCryptoSymmetricKey(const NSSCryptoSymmetricKey &);
00274     NSSCryptoSymmetricKey & operator= (const NSSCryptoSymmetricKey &);
00275 
00276     int decryptCtxInit(const unsigned char * iv);
00277 
00278     SymmetricKeyType                m_keyType;
00279     SymmetricKeyMode                m_keyMode;      // ECB or CBC
00280     bool                              m_initialised;
00281     bool                            m_doPad; //Does we need it?  Yes we do - key wraps are unpadded for 3DES
00282 
00283     unsigned char                   m_lastBlock[NSS_MAX_BLOCK_SIZE];
00284     unsigned int                    m_blockSize;
00285   bool                              m_ivSent;       // Has the IV been put in the stream
00286     unsigned int                    m_ivSize;
00287 
00288   PK11Context *         mp_ctx;
00289     PK11SymKey *                  mp_k;
00290 
00291 };
00292 
00293 #endif /* HAVE_NSS */
00294 #endif /* NSSCRYPTOSYMMETRICKEY_INCLUDE */

Generated on Sun Jan 28 19:37:22 2007 for XML-Security-C by  doxygen 1.4.2